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
type CategoryAttribute = class
    inherit Attribute
Public Class CategoryAttribute
Inherits Attribute
繼承
CategoryAttribute
屬性

範例

下列範例會建立MyImage屬性。The following example creates the MyImage property. 屬性有兩個屬性: DescriptionAttribute CategoryAttribute和。The 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索引, MyImage以取得。Next, the code indexes into the PropertyDescriptorCollection to get MyImage. 然後, 它會傳回這個屬性的屬性, 並將其儲存attributes在變數中。Then 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)

備註

當清單Categorized中的屬性或事件設定為模式時,表示要與相關聯的屬性或事件產生關聯的類別。CategoryAttribute PropertyGridA 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. 如果尚未套用至屬性或事件, 會將PropertyGrid它與 [其他] 分類產生關聯。CategoryAttributeIf a CategoryAttribute has not been applied to a property or event, the PropertyGrid associates it with the Misc category. 藉由在的函式中CategoryAttribute指定分類名稱, 可以為任何名稱建立新的類別。A 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

取得代表動作分類的 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

取得代表行為分類的 CategoryAttributeGets a CategoryAttribute representing the Behavior category.

Category

取得屬性 (Property) 分類的名稱或與這個屬性 (Attribute) 所套用的事件。Gets the name of the category for the property or event that this attribute is applied to.

Data

取得代表資料分類的 CategoryAttributeGets a CategoryAttribute representing the Data category.

Default

取得代表預設分類的 CategoryAttributeGets a CategoryAttribute representing the Default category.

Design

取得代表設計分類的 CategoryAttributeGets a CategoryAttribute representing the Design category.

DragDrop

取得代表拖放分類的 CategoryAttributeGets a CategoryAttribute representing the DragDrop category.

Focus

取得代表焦點分類的 CategoryAttributeGets a CategoryAttribute representing the Focus category.

Format

取得代表格式分類的 CategoryAttributeGets a CategoryAttribute representing the Format category.

Key

取得代表索引鍵分類的 CategoryAttributeGets a CategoryAttribute representing the Key category.

Layout

取得代表配置分類的 CategoryAttributeGets a CategoryAttribute representing the Layout category.

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

取得代表視窗樣式分類的 CategoryAttributeGets a CategoryAttribute representing the WindowStyle category.

方法

Equals(Object)

傳回值,表示指定的物件值是否等於目前的 CategoryAttributeReturns whether the value of the given object is equal to the current CategoryAttribute.

GetHashCode()

傳回這個屬性的雜湊碼。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.

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)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。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)

適用於

另請參閱