Export (0) Print
Expand All

DesignerAttribute Class

Specifies the class used to implement design-time services for a component.

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

[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface, AllowMultiple=true, Inherited=true)] 
public sealed class DesignerAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface, AllowMultiple=true, Inherited=true) */ 
public final class DesignerAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface, AllowMultiple=true, Inherited=true) 
public final class DesignerAttribute extends Attribute
Not applicable.

The class you use for the design-time services must implement the IDesigner interface.

Use the DesignerBaseTypeName property to find the designer's base type. Use the DesignerTypeName property to get the name of the type of designer associated with this member.

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.DLL", 
    typeof(IRootDesigner)),
    DesignerCategory("Form")]
public class MyForm : ContainerControl {
    // Insert code here.
}

/** @attribute Designer("System.Windows.Forms.Design.DocumentDesigner,"+
    "System.Windows.Forms.Design.DLL", 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 DesignerAttribute, 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 DesignerAttribute
     * from the AttributeCollection. */
    DesignerAttribute myAttribute = 
       (DesignerAttribute)attributes[typeof(DesignerAttribute)];
    Console.WriteLine("The designer for this class is: " + myAttribute.DesignerTypeName);
  
    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 
       DesignerAttribute from the AttributeCollection. 
     */
    DesignerAttribute myAttribute = (DesignerAttribute)(
        attributes.get_Item(DesignerAttribute.class.ToType()));

    Console.WriteLine(("The designer for this class is: " 
        + myAttribute.get_DesignerTypeName()));
} //main

System.Object
   System.Attribute
    System.ComponentModel.DesignerAttribute

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 Millennium Edition, 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

Community Additions

ADD
Show:
© 2014 Microsoft