PropertyTabAttribute 类

定义

标识要为指定的类显示的属性选项卡。

public ref class PropertyTabAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public class PropertyTabAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type PropertyTabAttribute = class
    inherit Attribute
Public Class PropertyTabAttribute
Inherits Attribute
继承
PropertyTabAttribute
属性

示例

下面的代码示例演示如何使用 PropertyTabAttribute 指定属性选项卡。代码示例定义一个组件,该组件按类型公开另一个选定组件的属性。

#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Reflection;
using namespace System::Runtime::Serialization;
using namespace System::Runtime::Serialization::Formatters::Binary;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::Design;
using namespace System::Security::Permissions;

namespace TypeCategoryTabExample
{
   ref class TypeCategoryTab;

   // forward declaration.
   // This component adds a TypeCategoryTab to the propery browser
   // that is available for any components in the current design mode document.

   [PropertyTabAttribute(TypeCategoryTabExample::TypeCategoryTab::typeid,PropertyTabScope::Document)]
   public ref class TypeCategoryTabComponent: public System::ComponentModel::Component
   {
   public:
      TypeCategoryTabComponent(){}
   };

   // A TypeCategoryTab property tab lists properties by the
   // category of the type of each property.
   public ref class TypeCategoryTab: public PropertyTab
   {
   private:

      // This String^ contains a Base-64 encoded and serialized example property tab image.

      [BrowsableAttribute(true)]
      String^ img;

   public:
      TypeCategoryTab()
      {
         img = "AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuMzMwMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAA9gAAAAJCTfYAAAAAAAAANgAAACgAAAAIAAAACAAAAAEAGAAAAAAAAAAAAMQOAADEDgAAAAAAAAAAAAD///////////////////////////////////9ZgABZgADzPz/zPz/zPz9AgP//////////gAD/gAD/AAD/AAD/AACKyub///////+AAACAAAAAAP8AAP8AAP9AgP////////9ZgABZgABz13hz13hz13hAgP//////////gAD/gACA/wCA/wCA/wAA//////////+AAACAAAAAAP8AAP8AAP9AgP////////////////////////////////////8L";
      }

      // Returns the properties of the specified component extended with
      // a CategoryAttribute reflecting the name of the type of the property.
      [ReflectionPermission(SecurityAction::Demand, Flags=ReflectionPermissionFlag::MemberAccess)]
      virtual System::ComponentModel::PropertyDescriptorCollection^ GetProperties( Object^ component, array<System::Attribute^>^attributes ) override
      {
         PropertyDescriptorCollection^ props;
         if ( attributes == nullptr )
                  props = TypeDescriptor::GetProperties( component );
         else
                  props = TypeDescriptor::GetProperties( component, attributes );

         array<PropertyDescriptor^>^propArray = gcnew array<PropertyDescriptor^>(props->Count);
         for ( int i = 0; i < props->Count; i++ )
         {
            // Create a new PropertyDescriptor from the old one, with
            // a CategoryAttribute matching the name of the type.
            array<Attribute^>^temp0 = {gcnew CategoryAttribute( props[ i ]->PropertyType->Name )};
            propArray[ i ] = TypeDescriptor::CreateProperty( props[ i ]->ComponentType, props[ i ], temp0 );

         }
         return gcnew PropertyDescriptorCollection( propArray );
      }

      virtual System::ComponentModel::PropertyDescriptorCollection^ GetProperties( Object^ component ) override
      {
         return this->GetProperties( component, nullptr );
      }

      property String^ TabName 
      {
         // Provides the name for the property tab.
         virtual String^ get() override
         {
            return "Properties by Type";
         }
      }

      property System::Drawing::Bitmap^ Bitmap 
      {
         // Provides an image for the property tab.
         virtual System::Drawing::Bitmap^ get() override
         {
            System::Drawing::Bitmap^ bmp = gcnew System::Drawing::Bitmap( DeserializeFromBase64Text( img ) );
            return bmp;
         }
      }

   private:

      // This method can be used to retrieve an Image from a block of Base64-encoded text.
      Image^ DeserializeFromBase64Text( String^ text )
      {
         Image^ img = nullptr;
         array<Byte>^memBytes = Convert::FromBase64String( text );
         IFormatter^ formatter = gcnew BinaryFormatter;
         MemoryStream^ stream = gcnew MemoryStream( memBytes );
         img = dynamic_cast<Image^>(formatter->Deserialize( stream ));
         stream->Close();
         return img;
      }
   };
}
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace TypeCategoryTabExample
{	
    // This component adds a TypeCategoryTab to the property browser 
    // that is available for any components in the current design mode document.
    [PropertyTabAttribute(typeof(TypeCategoryTab), PropertyTabScope.Document)]
    public class TypeCategoryTabComponent : System.ComponentModel.Component
    {           
        public TypeCategoryTabComponent()
        {
        }
    }

    // A TypeCategoryTab property tab lists properties by the 
    // category of the type of each property.
    public class TypeCategoryTab : PropertyTab
    {
        [BrowsableAttribute(true)]
        // This string contains a Base-64 encoded and serialized example property tab image.
        private string img = "AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuMzMwMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAA9gAAAAJCTfYAAAAAAAAANgAAACgAAAAIAAAACAAAAAEAGAAAAAAAAAAAAMQOAADEDgAAAAAAAAAAAAD///////////////////////////////////9ZgABZgADzPz/zPz/zPz9AgP//////////gAD/gAD/AAD/AAD/AACKyub///////+AAACAAAAAAP8AAP8AAP9AgP////////9ZgABZgABz13hz13hz13hAgP//////////gAD/gACA/wCA/wCA/wAA//////////+AAACAAAAAAP8AAP8AAP9AgP////////////////////////////////////8L";

        public TypeCategoryTab()
        {            
        }

        // Returns the properties of the specified component extended with 
        // a CategoryAttribute reflecting the name of the type of the property.
        public override System.ComponentModel.PropertyDescriptorCollection GetProperties(object component, System.Attribute[] attributes)
        {
            PropertyDescriptorCollection props;
            if( attributes == null )
                props = TypeDescriptor.GetProperties(component);    
            else
                props = TypeDescriptor.GetProperties(component, attributes);    
            
            PropertyDescriptor[] propArray = new PropertyDescriptor[props.Count];            
            for(int i=0; i<props.Count; i++)           
            {                
                // Create a new PropertyDescriptor from the old one, with 
                // a CategoryAttribute matching the name of the type.
                propArray[i] = TypeDescriptor.CreateProperty(props[i].ComponentType, props[i], new CategoryAttribute(props[i].PropertyType.Name));
            }
            return new PropertyDescriptorCollection( propArray );
        }

        public override System.ComponentModel.PropertyDescriptorCollection GetProperties(object component)
        {                     
            return this.GetProperties(component, null);
        }

        // Provides the name for the property tab.
        public override string TabName
        {
            get
            {
                return "Properties by Type";
            }
        }

        // Provides an image for the property tab.
        public override System.Drawing.Bitmap Bitmap
        {
            get
            {
                Bitmap bmp = new Bitmap(DeserializeFromBase64Text(img));
                return bmp;
            }
        }

        // This method can be used to retrieve an Image from a block of Base64-encoded text.
        private Image DeserializeFromBase64Text(string text)
        {
            Image img = null;
            byte[] memBytes = Convert.FromBase64String(text);
            IFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream(memBytes);
            img = (Image)formatter.Deserialize(stream);
            stream.Close();
            return img;
        }
    }
}
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.IO
Imports System.Reflection
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Windows.Forms
Imports System.Windows.Forms.Design

' This component adds a TypeCategoryTab to the property browser
' that is available for any components in the current design mode document.
<PropertyTabAttribute(GetType(TypeCategoryTab), PropertyTabScope.Document)>  _
Public Class TypeCategoryTabComponent
   Inherits System.ComponentModel.Component
   
   Public Sub New()
    End Sub
End Class

' A TypeCategoryTab property tab lists properties by the 
' category of the type of each property.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Public Class TypeCategoryTab
    Inherits PropertyTab

    ' This string contains a Base-64 encoded and serialized example property tab image.
    <BrowsableAttribute(True)> _
    Private img As String = "AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuMzMwMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAA9gAAAAJCTfYAAAAAAAAANgAAACgAAAAIAAAACAAAAAEAGAAAAAAAAAAAAMQOAADEDgAAAAAAAAAAAAD///////////////////////////////////9ZgABZgADzPz/zPz/zPz9AgP//////////gAD/gAD/AAD/AAD/AACKyub///////+AAACAAAAAAP8AAP8AAP9AgP////////9ZgABZgABz13hz13hz13hAgP//////////gAD/gACA/wCA/wCA/wAA//////////+AAACAAAAAAP8AAP8AAP9AgP////////////////////////////////////8L"

    Public Sub New()
    End Sub

    ' Returns the properties of the specified component extended with 
    ' a CategoryAttribute reflecting the name of the type of the property.
    Public Overloads Overrides Function GetProperties(ByVal component As Object, ByVal attributes() As System.Attribute) As System.ComponentModel.PropertyDescriptorCollection
        Dim props As PropertyDescriptorCollection
        If attributes Is Nothing Then
            props = TypeDescriptor.GetProperties(component)
        Else
            props = TypeDescriptor.GetProperties(component, attributes)
        End If
        Dim propArray(props.Count - 1) As PropertyDescriptor
        Dim i As Integer
        For i = 0 To props.Count - 1
            ' Create a new PropertyDescriptor from the old one, with 
            ' a CategoryAttribute matching the name of the type.
            propArray(i) = TypeDescriptor.CreateProperty(props(i).ComponentType, props(i), New CategoryAttribute(props(i).PropertyType.Name))
        Next i
        Return New PropertyDescriptorCollection(propArray)
    End Function

    Public Overloads Overrides Function GetProperties(ByVal component As Object) As System.ComponentModel.PropertyDescriptorCollection
        Return Me.GetProperties(component, Nothing)
    End Function

    ' Provides the name for the property tab.
    Public Overrides ReadOnly Property TabName() As String
        Get
            Return "Properties by Type"
        End Get
    End Property

    ' Provides an image for the property tab.
    Public Overrides ReadOnly Property Bitmap() As System.Drawing.Bitmap
        Get
            Dim bmp As New Bitmap(DeserializeFromBase64Text(img))
            Return bmp
        End Get
    End Property

    ' This method can be used to retrieve an Image from a block of Base64-encoded text.
    Private Function DeserializeFromBase64Text(ByVal [text] As String) As Image
        Dim img As Image = Nothing
        Dim memBytes As Byte() = Convert.FromBase64String([text])
        Dim formatter As New BinaryFormatter()
        Dim stream As New MemoryStream(memBytes)
        img = CType(formatter.Deserialize(stream), Image)
        stream.Close()
        Return img
    End Function
End Class

注解

通过它 PropertyTabAttribute 可将新属性页添加到 PropertyGrid 控件。 可以 PropertyTabAttribute 添加其他属性选项卡来公开组件的默认属性集以外的属性信息。

构造函数

PropertyTabAttribute()

初始化 PropertyTabAttribute 类的新实例。

PropertyTabAttribute(String)

使用指定的选项卡类名称初始化 PropertyTabAttribute 类的新实例。

PropertyTabAttribute(String, PropertyTabScope)

使用指定的选项卡类名和选项卡范围初始化 PropertyTabAttribute 类的新实例。

PropertyTabAttribute(Type)

使用指定的选项卡类型初始化 PropertyTabAttribute 类的新实例。

PropertyTabAttribute(Type, PropertyTabScope)

使用指定的选项卡类型和选项卡范围初始化 PropertyTabAttribute 类的新实例。

属性

TabClasses

获取此特性使用的选项卡的类型。

TabClassNames

获取此特性使用的选项卡类的名称。

TabScopes

获取该 PropertyTabAttribute 的每个选项卡的选项卡范围数组。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否等于指定的对象。

Equals(PropertyTabAttribute)

返回一个值,该值指示此实例是否与指定的特性相等。

GetHashCode()

获取此对象的哈希代码。

GetType()

获取当前实例的 Type

(继承自 Object)
InitializeArrays(String[], PropertyTabScope[])

使用指定的选项卡类名称和选项卡范围数组初始化该特性。

InitializeArrays(Type[], PropertyTabScope[])

使用指定的选项卡类名称和选项卡范围数组初始化该特性。

IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于