CategoryAttribute 类

定义

指定当属性或事件显示在一个设置为“按分类顺序”模式的 PropertyGrid 控件中时,用于对属性或事件分组的类别的名称。Specifies the name of the category in which to group the property or event when displayed in a PropertyGrid control set to Categorized mode.

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

示例

下面的示例创建 MyImage 属性。The following example creates the MyImage property. 属性具有两个属性: DescriptionAttributeCategoryAttributeThe property has two attributes: a DescriptionAttribute and a CategoryAttribute.

   [Description("The image associated with the control"),Category("Appearance")]
   System::Drawing::Image^ get()
   {
      // Insert code here.
      return m_Image1;
   }

   void set( System::Drawing::Image^ )
   {
      // Insert code here.
   }
}
[Description("The image associated with the control"),Category("Appearance")] 
 public Image MyImage {
    get {
       // Insert code here.
       return image1;
    }
    set {
       // Insert code here.
    }
 }
<Description("The image associated with the control"), _
    Category("Appearance")> _
Public Property MyImage() As Image
    
    Get
        ' Insert code here.
        Return image1
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

下一个示例获取的类别 MyImageThe next example gets the category for MyImage. 首先,该代码获取一个, PropertyDescriptorCollection 其中包含对象的所有属性。First, the code gets a PropertyDescriptorCollection with all the properties for the object. 接下来,代码将索引到中 PropertyDescriptorCollection 以获取 MyImageNext, the code indexes into the PropertyDescriptorCollection to get MyImage. 然后,它将返回此属性的属性并将其保存在变量中 attributesThen it returns the attributes for this property and saves them in the variable attributes.

然后,该示例通过 CategoryAttribute 从检索 AttributeCollection ,并将其写入控制台屏幕来打印该类别。The example then prints the category by retrieving CategoryAttribute from the AttributeCollection, and writing it to the console screen.

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyImage" ]->Attributes;

// Prints the description by retrieving the CategoryAttribute.
// from the AttributeCollection.
CategoryAttribute^ myAttribute = static_cast<CategoryAttribute^>(attributes[ CategoryAttribute::typeid ]);
Console::WriteLine( myAttribute->Category );
// Gets the attributes for the property.
 AttributeCollection attributes = 
    TypeDescriptor.GetProperties(this)["MyImage"].Attributes;
 
 // Prints the description by retrieving the CategoryAttribute.
 // from the AttributeCollection.
 CategoryAttribute myAttribute = 
    (CategoryAttribute)attributes[typeof(CategoryAttribute)];
 Console.WriteLine(myAttribute.Category);
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("MyImage").Attributes

' Prints the description by retrieving the CategoryAttribute. 
' from the AttributeCollection.
Dim myAttribute As CategoryAttribute = _
    CType(attributes(GetType(CategoryAttribute)), CategoryAttribute)
    Console.WriteLine(myAttribute.Category)

注解

CategoryAttribute当将控件中的属性或事件列出到模式时,指示要与关联的属性或事件关联的类别 PropertyGrid CategorizedA CategoryAttribute indicates the category to associate the associated property or event with, when listing properties or events in a PropertyGrid control set to Categorized mode. 如果尚未 CategoryAttribute 应用于属性或事件,则 PropertyGrid 会将其与 " 杂项 " 类别关联。If a CategoryAttribute has not been applied to a property or event, the PropertyGrid associates it with the Misc category. 可以通过在的构造函数中指定类别的名称,为任何名称创建一个新类别 CategoryAttributeA new category can be created for any name by specifying the name of the category in the constructor for the CategoryAttribute.

Category属性指示该属性表示的类别的名称。The Category property indicates the name of the category that the attribute represents. Category属性还提供了类别名称的透明本地化。The Category property also provides transparent localization of category names.

继承者说明

如果使用的类别名称不是预定义的名称,并且要本地化类别名称,则必须重写 GetLocalizedString(String) 方法。If you use category names other than the predefined names, and you want to localize your category names, you must override the GetLocalizedString(String) method.

CategoryAttribute类定义以下常见类别:The CategoryAttribute class defines the following common categories:

类别Category 说明Description
Action 与可用操作相关的属性。Properties related to available actions.
Appearance 与实体显示方式相关的属性。Properties related to how an entity appears.
Behavior 与实体的作用方式相关的属性。Properties related to how an entity acts.
Data 与数据和数据源管理相关的属性。Properties related to data and data source management.
Default 分组到默认类别中的属性。Properties that are grouped in a default category.
Design 仅在设计时可用的属性。Properties that are available only at design time.
DragDrop 与拖放操作相关的属性。Properties related to drag-and-drop operations.
Focus 与焦点相关的属性。Properties related to focus.
Format 与格式设置相关的属性。Properties related to formatting.
Key 与键盘相关的属性。Properties related to the keyboard.
Layout 与布局相关的属性。Properties related to layout.
Mouse 与鼠标相关的属性。Properties related to the mouse.
WindowStyle 与顶级窗体的窗口样式相关的属性。Properties related to the window style of top-level forms.

有关更多信息,请参阅特性For more information, see Attributes.

构造函数

CategoryAttribute()

使用类别名称"Default"初始化 CategoryAttribute 类的新实例。Initializes a new instance of the CategoryAttribute class using the category name Default.

CategoryAttribute(String)

使用指定的类别名称初始化 CategoryAttribute 类的新实例。Initializes a new instance of the CategoryAttribute class using the specified category name.

属性

Action

获取表示"Action"类别的 CategoryAttributeGets a CategoryAttribute representing the Action category.

Appearance

获取表示"Appearance"类别的 CategoryAttributeGets a CategoryAttribute representing the Appearance category.

Asynchronous

获取表示"Asynchronous"类别的 CategoryAttributeGets a CategoryAttribute representing the Asynchronous category.

Behavior

获取表示"Behavior"类别的 CategoryAttributeGets a CategoryAttribute representing the Behavior category.

Category

获取此属性 (Attribute) 应用于的属性 (Property) 或事件的类别名称。Gets the name of the category for the property or event that this attribute is applied to.

Data

获取表示"Data"类别的 CategoryAttributeGets a CategoryAttribute representing the Data category.

Default

获取表示"Default"类别的 CategoryAttributeGets a CategoryAttribute representing the Default category.

Design

获取表示"Design"类别的 CategoryAttributeGets a CategoryAttribute representing the Design category.

DragDrop

获取表示"DragDrop"类别的 CategoryAttributeGets a CategoryAttribute representing the DragDrop category.

Focus

获取表示"Focus"类别的 CategoryAttributeGets a CategoryAttribute representing the Focus category.

Format

获取表示"Format"类别的 CategoryAttributeGets a CategoryAttribute representing the Format category.

Key

获取表示"Key"类别的 CategoryAttributeGets a CategoryAttribute representing the Key category.

Layout

获取表示"Layout"类别的 CategoryAttributeGets a CategoryAttribute representing the Layout category.

Mouse

获取表示"Mouse"类别的 CategoryAttributeGets a CategoryAttribute representing the Mouse category.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)
WindowStyle

获取表示"WindowStyle"类别的 CategoryAttributeGets a CategoryAttribute representing the WindowStyle category.

方法

Equals(Object)

返回给定对象的值是否等于当前的 CategoryAttributeReturns whether the value of the given object is equal to the current CategoryAttribute.

GetHashCode()

返回此属性 (Attribute) 的哈希代码。Returns the hash code for this attribute.

GetLocalizedString(String)

查阅指定类别的本地化名称。Looks up the localized name of the specified category.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDefaultAttribute()

确定此特性是否为默认特性。Determines if this attribute is the default.

IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

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

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

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

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

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

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

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

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于

另请参阅