DesignerCategoryAttribute Class
Assembly: System (in system.dll)
'Declaration <AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple:=False, Inherited:=True)> _ Public NotInheritable Class DesignerCategoryAttribute Inherits Attribute 'Usage Dim instance As DesignerCategoryAttribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true) */ public final class DesignerCategoryAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true) public final class DesignerCategoryAttribute extends Attribute
Not applicable.
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.
The DesignerCategoryAttribute class defines the following common categories:
| Category | Description |
|---|---|
| Component | Designers that are used with components. The attribute is set to the constant member DesignerCategoryAttribute.Component. |
| Form | Designers that are used with forms. The attribute is set to the constant member DesignerCategoryAttribute.Form. |
| Designer | Designers that are used with designers. The attribute is set to the constant member DesignerCategoryAttribute.Generic. |
| Empty String ("") | This is the default category. |
For more information, see Attributes Overview and Extending Metadata Using Attributes.
The following example creates a class called MyForm. 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", _ GetType(IRootDesigner)), DesignerCategory("Form")> _ Public Class MyForm Inherits ContainerControl ' Insert code here. End Class 'MyForm
/** @attribute Designer("System.Windows.Forms.Design.DocumentDesigner, "
+ "System.Windows.Forms.Design", IRootDesigner.class)
@attribute DesignerCategory("Form")
*/
public static class MyForm extends ContainerControl
{
// Insert code here.
} //MyForm
The next example creates an instance of MyForm. Then it gets the attributes for the class, extracts the DesignerCategoryAttribute, and prints the name of the designer.
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
public static void main(String[] args)
{
// 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.get_Item(DesignerCategoryAttribute.class.ToType()));
Console.WriteLine("The category of the designer "
+ "for this class is: " + myAttribute.get_Category());
} //main
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.