DesignerCategoryAttribute 類別

定義

指定類別的設計工具屬於特定的分類。

public ref class DesignerCategoryAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public sealed class DesignerCategoryAttribute : Attribute
public sealed class DesignerCategoryAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)>]
type DesignerCategoryAttribute = class
    inherit Attribute
type DesignerCategoryAttribute = class
    inherit Attribute
Public NotInheritable Class DesignerCategoryAttribute
Inherits Attribute
繼承
DesignerCategoryAttribute
屬性

範例

下列範例會建立名為 的 MyForm 類別。 MyForm 具有兩個 DesignerAttribute 屬性,指定這個類別的 DocumentDesigner 會使用 ,以及 DesignerCategoryAttribute 指定類別的 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 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 = 
       (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 會定義下列常見類別:

類別 描述
元件 與元件搭配使用的設計工具。 屬性會設定為常數成員 DesignerCategoryAttribute.Component
表單 與表單搭配使用的設計工具。 屬性會設定為常數成員 DesignerCategoryAttribute.Form
Designer 與設計工具搭配使用的設計工具。 屬性會設定為常數成員 DesignerCategoryAttribute.Generic
空字串 (「」) 這是預設類別。

如需詳細資訊,請參閱屬性

建構函式

DesignerCategoryAttribute()

使用空字串 ("") 來初始化 DesignerCategoryAttribute 類別的新執行個體。

DesignerCategoryAttribute(String)

使用指定的分類名稱來初始化 DesignerCategoryAttribute 類別的新執行個體。

欄位

Component

指定標記為這個分類的元件會使用元件設計工具。 此欄位為唯讀。

Default

指定標記為這個分類的元件無法使用視覺化設計工具。 這個 static 欄位是唯讀的。

Form

指定標記為這個分類的元件會使用表單設計工具。 這個 static 欄位是唯讀的。

Generic

指定標記為這個分類的元件會使用泛型設計工具。 這個 static 欄位是唯讀的。

屬性

Category

取得分類的名稱。

TypeId

取得這個屬性的唯一識別項。

TypeId

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

(繼承來源 Attribute)

方法

Equals(Object)

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

GetHashCode()

傳回這個執行個體的雜湊碼。

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)

適用於

另請參閱