CategoryAttribute 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定在設定為 [分類] 模式的 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
- 繼承
- 屬性
範例
以下範例會產生該 MyImage 性質。 該性質有兩個屬性:a DescriptionAttribute 和 CategoryAttributea。
[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.
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類別。 首先,程式碼會取得包含所有物件屬性的 a PropertyDescriptorCollection 。 接著,程式碼會索引到 PropertyDescriptorCollection 以取得 MyImage。 接著它會回傳該屬性的屬性,並將其儲存在變數 attributes中。
範例接著從 擷取 CategoryAttributeAttributeCollection,並寫入主控台畫面,來列印該類別。
// 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 A 表示在將屬性或事件PropertyGrid列入控制項設定為Categorized模式時,要關聯該屬性或事件的類別。 若 a CategoryAttribute 未被應用於某財產或事件,則 PropertyGrid 將其與 雜項 類別關聯。 只要在建構子 CategoryAttribute中指定該類別名稱,即可為任意名稱建立新的類別。
屬性 Category 表示該屬性所代表的類別名稱。 此 Category 特性同時提供類別名稱的透明本地化。
給繼承者的注意事項
如果你使用了非預設名稱的類別名稱,且想要本地化分類名稱,必須覆寫該 GetLocalizedString(String) 方法。
該 CategoryAttribute 類別定義了以下常見類別:
| Category | 描述 |
|---|---|
| Action | 與可用行動相關的屬性。 |
| Appearance | 與實體外觀相關的屬性。 |
| Behavior | 與實體行為相關的屬性。 |
| Data | 與資料及資料來源管理相關的屬性。 |
| Default | 這些屬性被歸類為預設類別。 |
| Design | 僅在設計時提供物業。 |
| DragDrop | 與拖放操作相關的特性。 |
| Focus | 與焦點相關的屬性。 |
| Format | 與格式相關的屬性。 |
| Key | 與鍵盤相關的屬性。 |
| Layout | 與版面配置相關的屬性。 |
| Mouse | 與老鼠相關的特性。 |
| WindowStyle | 與頂層表單視窗樣式相關的屬性。 |
如需詳細資訊,請參閱屬性。
建構函式
| 名稱 | Description |
|---|---|
| CategoryAttribute() |
使用類別名稱 Default 初始化該類別的新實例 CategoryAttribute 。 |
| CategoryAttribute(String) |
使用指定的類別名稱初始化該類別的新實例 CategoryAttribute 。 |
屬性
| 名稱 | Description |
|---|---|
| Action |
獲得代表行動類別的一個 CategoryAttribute 。 |
| Appearance |
獲得代表外觀類別的獎 CategoryAttribute 項。 |
| Asynchronous |
獲得 CategoryAttribute 代表非同步類別的一個。 |
| Behavior |
獲得 CategoryAttribute 代表行為類別的 A。 |
| Category |
取得該屬性所應用的屬性或事件的類別名稱。 |
| Data |
會得到 CategoryAttribute 代表資料類別的一個。 |
| Default |
獲得 CategoryAttribute 代表預設類別的 |
| Design |
代表 CategoryAttribute 設計類別。 |
| DragDrop |
會獲得 CategoryAttribute 代表 DragDrop 類別的 D。 |
| Focus |
獲得 CategoryAttribute 代表焦點類別的獎項。 |
| Format |
獲得 CategoryAttribute 代表格式類別的項目。 |
| Key |
獲得 CategoryAttribute 代表關鍵類別的作品。 |
| Layout |
會得到代表版面配置類別的一個 CategoryAttribute 。 |
| Mouse |
獲得 CategoryAttribute 代表滑鼠類別的獎項。 |
| TypeId |
在衍生類別中實作時,取得這個 Attribute的唯一標識碼。 (繼承來源 Attribute) |
| WindowStyle |
獲得 CategoryAttribute 代表 WindowStyle 類別的 |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
回傳給定物件的值是否等於當前 CategoryAttribute值。 |
| GetHashCode() |
回傳此屬性的雜湊碼。 |
| GetLocalizedString(String) |
查詢指定類別的在地名稱。 |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsDefaultAttribute() |
判斷此屬性是否為預設值。 |
| Match(Object) |
在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。 (繼承來源 Attribute) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| _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) |