Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DesignerCategoryAttribute Class

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

For a list of all members of this type, see DesignerCategoryAttribute Members.

System.Object
   System.Attribute
      System.ComponentModel.DesignerCategoryAttribute

[Visual Basic]
<AttributeUsage(AttributeTargets.Class)>
NotInheritable Public Class DesignerCategoryAttribute
   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Class)]
public sealed class DesignerCategoryAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Class)]
public __gc __sealed class DesignerCategoryAttribute : public
   Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Class)
class DesignerCategoryAttribute extends Attribute

Thread Safety

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

Remarks

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.

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
<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

[C#] 
[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design", 
    typeof(IRootDesigner)),
    DesignerCategory("Form")]
    
 public class MyForm : ContainerControl {
    // Insert code here.
 }

[C++] 
[Designer(S"System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design", 
          __typeof(IRootDesigner)),
          DesignerCategory(S"Form")]

__gc class MyForm : public ContainerControl {
    // Insert code here.
};

[Visual Basic, C#, C++] 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.

[Visual Basic] 
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

[C#] 
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;
}

[C++] 
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 = 
        dynamic_cast<DesignerCategoryAttribute*>(attributes->Item[__typeof(DesignerCategoryAttribute)]);
    Console::WriteLine(S"The category of the designer for this class is: {0}", myAttribute->Category);

    return 0;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System (in System.dll)

See Also

DesignerCategoryAttribute Members | System.ComponentModel Namespace | Attribute | DesignerAttribute

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.