DesignerCategoryAttribute Class
TOC
Collapse the table of content
Expand the table of content

DesignerCategoryAttribute Class

 

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

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

System.Object
  System.Attribute
    System.ComponentModel.DesignerCategoryAttribute

[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = false, 
	Inherited = true)]
public sealed class DesignerCategoryAttribute : Attribute

NameDescription
System_CAPS_pubmethodDesignerCategoryAttribute()

Initializes a new instance of the DesignerCategoryAttribute class with an empty string ("").

System_CAPS_pubmethodDesignerCategoryAttribute(String)

Initializes a new instance of the DesignerCategoryAttribute class with the given category name.

NameDescription
System_CAPS_pubpropertyCategory

Gets the name of the category.

System_CAPS_pubpropertyTypeId

This API supports the product infrastructure and is not intended to be used directly from your code. Gets a unique identifier for this attribute.(Overrides Attribute.TypeId.)

NameDescription
System_CAPS_pubmethodEquals(Object)

This API supports the product infrastructure and is not intended to be used directly from your code. Returns whether the value of the given object is equal to the current DesignOnlyAttribute.(Overrides Attribute.Equals(Object).)

System_CAPS_pubmethodGetHashCode()

This API supports the product infrastructure and is not intended to be used directly from your code. Returns the hash code for this instance.(Overrides Attribute.GetHashCode().)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodIsDefaultAttribute()

This API supports the product infrastructure and is not intended to be used directly from your code. Determines if this attribute is the default.(Overrides Attribute.IsDefaultAttribute().)

System_CAPS_pubmethodMatch(Object)

When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.(Inherited from Attribute.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticComponent

Specifies that a component marked with this category use a component designer. This field is read-only.

System_CAPS_pubfieldSystem_CAPS_staticDefault

This API supports the product infrastructure and is not intended to be used directly from your code. Specifies that a component marked with this category cannot use a visual designer. This static field is read-only.

System_CAPS_pubfieldSystem_CAPS_staticForm

Specifies that a component marked with this category use a form designer. This static field is read-only.

System_CAPS_pubfieldSystem_CAPS_staticGeneric

Specifies that a component marked with this category use a generic designer. This static field is read-only.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can be used to get the type information for an interface.(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.GetTypeInfoCount(UInt32)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.(Inherited from Attribute.)

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 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.
 }

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;
}

.NET Framework
Available since 1.1

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

Return to top
Show:
© 2016 Microsoft