CategoryAttribute 類別

定義

指定分類的名稱,該分類會在將 PropertyGrid 控制項設定為 [分類] 模式時,以群組方式來顯示屬性或事件。

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 建立 屬性。 屬性有兩個 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 它與Misc類別產生關聯。 您可以在 建構 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

取得代表動作分類的 CategoryAttribute

Appearance

取得代表 Appearance 分類的 CategoryAttribute

Asynchronous

取得代表 Asynchronous 分類的 CategoryAttribute

Behavior

取得代表行為分類的 CategoryAttribute

Category

取得屬性 (Property) 分類的名稱或與這個屬性 (Attribute) 所套用的事件。

Data

取得代表資料分類的 CategoryAttribute

Default

取得代表預設分類的 CategoryAttribute

Design

取得代表設計分類的 CategoryAttribute

DragDrop

取得代表拖放分類的 CategoryAttribute

Focus

取得代表焦點分類的 CategoryAttribute

Format

取得代表格式分類的 CategoryAttribute

Key

取得代表索引鍵分類的 CategoryAttribute

Layout

取得代表配置分類的 CategoryAttribute

Mouse

取得代表滑鼠分類的 CategoryAttribute

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)
WindowStyle

取得代表視窗樣式分類的 CategoryAttribute

方法

Equals(Object)

傳回值,表示指定的物件值是否等於目前的 CategoryAttribute

GetHashCode()

傳回這個屬性的雜湊碼。

GetLocalizedString(String)

查閱指定分類的當地語系化名稱。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

判斷這個屬性是否為預設值。

IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱