DesignerCategoryAttribute 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定類別的設計工具屬於特定類別。
public ref class DesignerCategoryAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public sealed class DesignerCategoryAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)>]
type DesignerCategoryAttribute = class
inherit Attribute
Public NotInheritable Class DesignerCategoryAttribute
Inherits Attribute
- 繼承
- 屬性
範例
以下範例會產生一個稱為 MyForm的類別。
MyForm有兩個屬性,a DesignerAttribute 指定此類別使用 ,a DocumentDesignerDesignerCategoryAttribute 指定Form類別。
[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design",
IRootDesigner::typeid),
DesignerCategory("Form")]
ref class MyForm: public ContainerControl{
// Insert code here.
};
[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design",
typeof(IRootDesigner)),
DesignerCategory("Form")]
public class MyForm : ContainerControl
{
// Insert code here.
}
<Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design", _
GetType(IRootDesigner)), DesignerCategory("Form")> _
Public Class MyForm
Inherits ContainerControl
' Insert code here.
End Class
下一個例子會產生一個 的 MyForm實例。 接著取得類別的屬性,擷取 DesignerCategoryAttribute,並列印設計師名稱。
int main()
{
// Creates a new form.
MyForm^ myNewForm = gcnew MyForm;
// Gets the attributes for the collection.
AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewForm );
/* Prints the name of the designer by retrieving the
* DesignerCategoryAttribute from the AttributeCollection. */
DesignerCategoryAttribute^ myAttribute = dynamic_cast<DesignerCategoryAttribute^>(attributes[ DesignerCategoryAttribute::typeid ]);
Console::WriteLine( "The category of the designer for this class is: {0}", myAttribute->Category );
return 0;
}
public static int Main()
{
// Creates a new form.
MyForm myNewForm = new();
// Gets the attributes for the collection.
AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewForm);
/* Prints the name of the designer by retrieving the
* DesignerCategoryAttribute from the AttributeCollection. */
DesignerCategoryAttribute myAttribute =
(DesignerCategoryAttribute)attributes[typeof(DesignerCategoryAttribute)];
Console.WriteLine("The category of the designer for this class is: " + myAttribute.Category);
return 0;
}
Public Shared Function Main() As Integer
' Creates a new form.
Dim myNewForm As New MyForm()
' Gets the attributes for the collection.
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewForm)
' Prints the name of the designer by retrieving the
' DesignerCategoryAttribute from the AttributeCollection.
Dim myAttribute As DesignerCategoryAttribute = _
CType(attributes(GetType(DesignerCategoryAttribute)), DesignerCategoryAttribute)
Console.WriteLine(("The category of the designer for this class is: " + myAttribute.Category))
Return 0
End Function 'Main
備註
視覺設計師可以使用設計師類別,向開發環境告知將實施的設計師類型。 若類別未提供設計類別,開發環境可能允許也可能不允許設計該類別。 任何名稱都可以建立一個類別。
當你用這個屬性標記類別時,它會被設定為常數成員。 當你想檢查程式碼中這個屬性的值時,必須指定常數成員。 下表中的描述欄位列出每個值所設定的常數成員。
該 DesignerCategoryAttribute 類別定義了以下常見類別:
| 類別 | Description |
|---|---|
| 組件 | 設計器是與元件一起使用的。 屬性設定為常數成員 DesignerCategoryAttribute.Component。 |
| Form | 設計師會使用表單。 屬性設定為常數成員 DesignerCategoryAttribute.Form。 |
| 設計師 | 設計師與設計師一起使用。 屬性設定為常數成員 DesignerCategoryAttribute.Generic。 |
| 空字串(“”) | 這是預設的類別。 |
如需詳細資訊,請參閱屬性。
建構函式
| 名稱 | Description |
|---|---|
| DesignerCategoryAttribute() |
初始化一個新的類別實例 DesignerCategoryAttribute ,使用空字串(“)。 |
| DesignerCategoryAttribute(String) |
初始化一個帶有該類別名稱的新類別實例 DesignerCategoryAttribute 。 |
欄位
| 名稱 | Description |
|---|---|
| Component |
指定標記為此類別的元件使用元件設計器。 此欄位僅供讀取。 |
| Default |
規定標記為此類別的元件不得使用視覺設計器。 此 |
| Form |
規定標記此類別的元件必須使用表單設計器。 此 |
| Generic |
規定標記此類別的元件使用通用設計器。 此 |
屬性
| 名稱 | Description |
|---|---|
| Category |
會得到該類別的名稱。 |
| TypeId |
會為此屬性取得唯一識別碼。 |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
回傳給定物件的值是否等於當前 DesignOnlyAttribute值。 |
| GetHashCode() |
傳回這個實例的哈希碼。 |
| 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) |