DesignerCategoryAttribute 類別
定義
指定類別的設計工具屬於特定的分類。Specifies that the designer for a class belongs to a certain category.
public ref class DesignerCategoryAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public sealed class DesignerCategoryAttribute : Attribute
type DesignerCategoryAttribute = class
inherit Attribute
Public NotInheritable Class DesignerCategoryAttribute
Inherits Attribute
- 繼承
- 屬性
範例
下列範例會建立名MyForm
為的類別。The following example creates a class called MyForm
. MyForm
有兩個屬性, DesignerAttribute指定此類別DocumentDesigner使用, Form以及DesignerCategoryAttribute指定類別目錄的。MyForm
has two attributes, a DesignerAttribute that specifies this class uses the DocumentDesigner, and a DesignerCategoryAttribute that specifies the Form category.
[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
。The next example creates an instance of MyForm
. 然後, 它會取得類別的屬性、解壓縮DesignerCategoryAttribute, 並列印設計工具的名稱。Then it gets the attributes for the class, extracts the DesignerCategoryAttribute, and prints the name of the designer.
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
備註
視覺化設計工具可以使用設計工具類別, 來通知將會實作為設計工具類型的開發環境。A visual designer can use a designer category to inform a development environment of the type of designer that will be implemented. 如果未在類別上提供任何設計工具類別, 開發環境可能會或可能不允許設計類別。If no designer category is provided on a class, a development environment may or may not allow the class to be designed. 可以為任何名稱建立類別目錄。A category can be created for any name.
當您使用這個屬性標記類別時, 它會設定為常數成員。When you mark a class with this attribute, it is set to a constant member. 當您想要在程式碼中檢查這個屬性的值時, 您必須指定常數成員。When you want to check the value of this attribute in your code, you must specify the constant member. 下表中的 [描述] 資料行列出每個值設定的常數成員。The Description column in the table below lists the constant member that each value is set to.
DesignerCategoryAttribute類別會定義下列通用分類:The DesignerCategoryAttribute class defines the following common categories:
分類Category | 說明Description |
---|---|
元件Component | 與元件搭配使用的設計工具。Designers that are used with components. 屬性會設定為常數成員DesignerCategoryAttribute.Component。The attribute is set to the constant member DesignerCategoryAttribute.Component. |
表單Form | 與表單搭配使用的設計工具。Designers that are used with forms. 屬性會設定為常數成員DesignerCategoryAttribute.Form。The attribute is set to the constant member DesignerCategoryAttribute.Form. |
DesignerDesigner | 與設計工具搭配使用的設計工具。Designers that are used with designers. 屬性會設定為常數成員DesignerCategoryAttribute.Generic。The attribute is set to the constant member DesignerCategoryAttribute.Generic. |
空字串 ("")Empty String ("") | 這是預設分類。This is the default category. |
如需詳細資訊,請參閱屬性。For more information, see Attributes.
建構函式
DesignerCategoryAttribute() |
使用空字串 ("") 來初始化 DesignerCategoryAttribute 類別的新執行個體。Initializes a new instance of the DesignerCategoryAttribute class with an empty string (""). |
DesignerCategoryAttribute(String) |
使用指定的分類名稱來初始化 DesignerCategoryAttribute 類別的新執行個體。Initializes a new instance of the DesignerCategoryAttribute class with the given category name. |
欄位
Component |
指定標記為這個分類的元件會使用元件設計工具。Specifies that a component marked with this category use a component designer. 此欄位為唯讀。This field is read-only. |
Default |
指定標記為這個分類的元件無法使用視覺化設計工具。Specifies that a component marked with this category cannot use a visual designer. 這個 |
Form |
指定標記為這個分類的元件會使用表單設計工具。Specifies that a component marked with this category use a form designer. 這個 |
Generic |
指定標記為這個分類的元件會使用泛型設計工具。Specifies that a component marked with this category use a generic designer. 這個 |
屬性
Category |
取得分類的名稱。Gets the name of the category. |
TypeId |
取得這個屬性的唯一識別項。Gets a unique identifier for this attribute. |
方法
Equals(Object) |
傳回值,表示指定的物件值是否等於目前的 DesignOnlyAttribute。Returns whether the value of the given object is equal to the current DesignOnlyAttribute. |
GetHashCode() |
傳回這個執行個體的雜湊碼。Returns the hash code for this instance. |
GetType() |
取得目前執行個體的 Type。Gets 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) |