Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DesignerCategoryAttribute Class

Specifies that the designer for a class belongs to a certain category.

Namespace: System.ComponentModel
Assembly: System (in system.dll)

[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true)] 
public sealed class DesignerCategoryAttribute : Attribute
/** @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", 
    typeof(IRootDesigner)),
    DesignerCategory("Form")]
    
 public class MyForm : ContainerControl {
    // Insert code here.
 }

/** @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 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 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

System.Object
   System.Attribute
    System.ComponentModel.DesignerCategoryAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft