CategoryAttribute 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定当属性或事件显示在一个设置为“按分类顺序”模式的 PropertyGrid 控件中时,用于对属性或事件分组的类别的名称。
public ref class CategoryAttribute : Attribute[System.AttributeUsage(System.AttributeTargets.All)]
public class CategoryAttribute : Attributepublic class CategoryAttribute : Attribute[<System.AttributeUsage(System.AttributeTargets.All)>]
type CategoryAttribute = class
    inherit Attributetype CategoryAttribute = class
    inherit AttributePublic Class CategoryAttribute
Inherits Attribute- 继承
- 属性
示例
以下示例创建 属性 MyImage 。 属性有两个CategoryAttribute属性:和 DescriptionAttribute 。
   [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
下一个示例获取 的 MyImage类别。 首先,代码获取 PropertyDescriptorCollection 包含 对象的所有属性的 。 接下来,将代码索引到 中 PropertyDescriptorCollection 以获取 MyImage。 然后,它返回此属性的属性,并将其保存在变量 attributes中。
然后,该示例通过从 AttributeCollection检索 CategoryAttribute 并将其写入控制台屏幕来打印类别。
// 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 属性或事件设置为 Categorized 模式时,要与关联的属性或事件关联的类别。 CategoryAttribute如果 尚未应用于属性或事件,则 PropertyGrid 将其与杂项类别相关联。 通过在 的 构造函数 CategoryAttribute中指定类别的名称,可以为任何名称创建新类别。
属性 Category 指示特性所表示的类别的名称。 属性 Category 还提供类别名称的透明本地化。
继承者说明
如果使用除预定义名称以外的类别名称,并且想要本地化类别名称,则必须重写 GetLocalizedString(String) 方法。
类 CategoryAttribute 定义以下常见类别:
| 类别 | 说明 | 
|---|---|
| Action | 与可用操作相关的属性。 | 
| Appearance | 与实体的显示方式相关的属性。 | 
| Behavior | 与实体行为方式相关的属性。 | 
| Data | 与数据和数据源管理相关的属性。 | 
| Default | 按默认类别分组的属性。 | 
| Design | 仅在设计时可用的属性。 | 
| DragDrop | 与拖放操作相关的属性。 | 
| Focus | 与焦点相关的属性。 | 
| Format | 与格式设置相关的属性。 | 
| Key | 与键盘相关的属性。 | 
| Layout | 与布局相关的属性。 | 
| Mouse | 与鼠标相关的属性。 | 
| WindowStyle | 与顶级窗体的窗口样式相关的属性。 | 
有关更多信息,请参阅特性。
构造函数
| CategoryAttribute() | 使用类别名称"Default"初始化 CategoryAttribute 类的新实例。 | 
| CategoryAttribute(String) | 使用指定的类别名称初始化 CategoryAttribute 类的新实例。 | 
属性
| Action | 获取表示"Action"类别的 CategoryAttribute。 | 
| Appearance | 获取表示"Appearance"类别的 CategoryAttribute。 | 
| Asynchronous | 获取表示"Asynchronous"类别的 CategoryAttribute。 | 
| Behavior | 获取表示"Behavior"类别的 CategoryAttribute。 | 
| Category | 获取此属性 (Attribute) 应用于的属性 (Property) 或事件的类别名称。 | 
| Data | 获取表示"Data"类别的 CategoryAttribute。 | 
| Default | 获取表示"Default"类别的 CategoryAttribute。 | 
| Design | 获取表示"Design"类别的 CategoryAttribute。 | 
| DragDrop | 获取表示"DragDrop"类别的 CategoryAttribute。 | 
| Focus | 获取表示"Focus"类别的 CategoryAttribute。 | 
| Format | 获取表示"Format"类别的 CategoryAttribute。 | 
| Key | 获取表示"Key"类别的 CategoryAttribute。 | 
| Layout | 获取表示"Layout"类别的 CategoryAttribute。 | 
| Mouse | 获取表示"Mouse"类别的 CategoryAttribute。 | 
| TypeId | 在派生类中实现时,获取此 Attribute 的唯一标识符。(继承自 Attribute) | 
| WindowStyle | 获取表示"WindowStyle"类别的 CategoryAttribute。 | 
方法
| Equals(Object) | 返回给定对象的值是否等于当前的 CategoryAttribute。 | 
| GetHashCode() | 返回此属性 (Attribute) 的哈希代码。 | 
| GetLocalizedString(String) | 查阅指定类别的本地化名称。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| IsDefaultAttribute() | 确定此特性是否为默认特性。 | 
| 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) |