指定在其中进行分组的属性或事件中显示的类别的名称 PropertyGrid 控件设置为按分类顺序模式。

命名空间:                   System.ComponentModel
程序集:         System(位于 System.dll)

继承层次结构

System.Object
System.Attribute
System.ComponentModel.CategoryAttribute

[AttributeUsageAttribute(AttributeTargets.All)]
public class CategoryAttribute : Attribute

构造函数


名称 说明
System_CAPS_pubmethod CategoryAttribute()

新实例初始化 CategoryAttribute 类使用的类别名称默认值。

System_CAPS_pubmethod CategoryAttribute(String)

新实例初始化 CategoryAttribute 类使用指定的类别名称。

属性


名称 说明
System_CAPS_pubpropertySystem_CAPS_static Action

获取 CategoryAttribute 表示的操作类别。

System_CAPS_pubpropertySystem_CAPS_static Appearance

获取 CategoryAttribute 表示外观类别。

System_CAPS_pubpropertySystem_CAPS_static Asynchronous

获取 CategoryAttribute 表示异步类别。

System_CAPS_pubpropertySystem_CAPS_static Behavior

获取 CategoryAttribute 表示行为类别。

System_CAPS_pubproperty Category

获取的属性或此特性应用于事件的类别的名称。

System_CAPS_pubpropertySystem_CAPS_static Data

获取 CategoryAttribute 表示数据类别。

System_CAPS_pubpropertySystem_CAPS_static Default

获取 CategoryAttribute 表示默认类别。

System_CAPS_pubpropertySystem_CAPS_static Design

获取 CategoryAttribute 表示设计类别。

System_CAPS_pubpropertySystem_CAPS_static DragDrop

获取 CategoryAttribute 表示拖放类别。

System_CAPS_pubpropertySystem_CAPS_static Focus

获取 CategoryAttribute 表示焦点类别。

System_CAPS_pubpropertySystem_CAPS_static Format

获取 CategoryAttribute 表示格式类别。

System_CAPS_pubpropertySystem_CAPS_static Key

获取 CategoryAttribute 表示键类别。

System_CAPS_pubpropertySystem_CAPS_static Layout

获取 CategoryAttribute 表示布局类别。

System_CAPS_pubpropertySystem_CAPS_static Mouse

获取 CategoryAttribute 表示鼠标类别。

System_CAPS_pubproperty TypeId

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

System_CAPS_pubpropertySystem_CAPS_static WindowStyle

获取 CategoryAttribute 表示 WindowStyle 类别。

方法


名称 说明
System_CAPS_pubmethod Equals(Object)

返回给定对象的值是否等于当前 CategoryAttribute...(覆盖 Attribute.Equals(Object)。)

System_CAPS_protmethod Finalize()

在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。(继承自 Object。)

System_CAPS_pubmethod GetHashCode()

返回此属性的哈希代码。(覆盖 Attribute.GetHashCode()。)

System_CAPS_protmethod GetLocalizedString(String)

查找指定类别的本地化名称。

System_CAPS_pubmethod GetType()

获取当前实例的 Type。(继承自 Object。)

System_CAPS_pubmethod IsDefaultAttribute()

确定此属性是否为默认值。(覆盖 Attribute.IsDefaultAttribute()。)

System_CAPS_pubmethod Match(Object)

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

System_CAPS_protmethod MemberwiseClone()

创建当前 Object 的浅表副本。(继承自 Object。)

System_CAPS_pubmethod ToString()

返回表示当前对象的字符串。(继承自 Object。)

显式接口实现


名称 说明
System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetIDsOfNames(Guid,IntPtr,UInt32,UInt32,IntPtr)

将一组名称映射为对应的一组调度标识符。(继承自 Attribute。)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfo(UInt32,UInt32,IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。(继承自 Attribute。)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfoCount(UInt32)

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

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.Invoke(UInt32,Guid,UInt32,Int16,IntPtr,IntPtr,IntPtr,IntPtr)

提供对某一对象公开的属性和方法的访问。(继承自 Attribute。)

备注

一个 CategoryAttribute 表示将关联的属性或事件,相关联的类别列出属性或中的事件时 PropertyGrid 控件设置为 Categorized 模式。 如果 CategoryAttribute 尚未应用到属性或事件时, PropertyGrid 将其与相关联 杂项 类别。 可以通过指定的类别名称的构造函数中的任何名称创建新类别 CategoryAttribute

 Category 属性指示该属性表示类别的名称。  Category 属性还提供了透明本地化的类别名称。

继承函数说明:

如果您使用预定义的名称以外的类别名称,并且您想要本地化类别名称,必须重写 GetLocalizedString 方法。

 CategoryAttribute 类定义了以下常见类别︰

类别

描述

Action

可用操作与相关的属性。

Appearance

与实体的显示方式相关的属性。

Behavior

与实体的行为相关的属性。

Data

对数据和数据源管理相关的属性。

Default

在默认类别中的分组的属性。

Design

只能在设计时是可用的属性。

DragDrop

与拖放操作相关的属性。

Focus

重点介绍相关的属性。

Format

对格式设置相关的属性。

Key

与键盘相关的属性。

Layout

为布局相关的属性。

Mouse

鼠标与相关的属性。

WindowStyle

为顶层窗体的窗口样式相关的属性。

示例

下面的示例创建 MyImage 属性。 该属性具有两个属性︰ DescriptionAttribute 和 CategoryAttribute

[Description("The p_w_picpath associated with the control"),Category("Appearance")] 
 public Image MyImage {    
 get {       
 // Insert code here.
       return p_w_picpath1;
    }    
 set {      
     // Insert code here.
    }
 }

下一个示例获取的类别 MyImage 首先,此代码可获取 PropertyDescriptorCollection 的对象的所有属性。 接下来,代码索引 PropertyDescriptorCollection 获取 MyImage 然后它将返回此属性的属性,并将它们保存在变量中 attributes

该示例然后通过检索输出类别 CategoryAttribute 从 AttributeCollection, ,并将它写入到控制台屏幕。

// 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);


备注:转自https://msdn.microsoft.com/zh-cn/library/system.componentmodel.categoryattribute(v=vs.110).aspx