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.

DesignerAttribute Class

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

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

System.Object
   System.Attribute
      System.ComponentModel.DesignerAttribute

[Visual Basic]
<AttributeUsage(AttributeTargets.Class Or _
   AttributeTargets.Interface)>
NotInheritable Public Class DesignerAttribute
   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Class |
   AttributeTargets.Interface)]
public sealed class DesignerAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Class |
   AttributeTargets::Interface)]
public __gc __sealed class DesignerAttribute : public Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)
class DesignerAttribute 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

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.

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

[C++] 
[Designer(S"System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL", 
          __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 DesignerAttribute, 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 DesignerAttribute
    ' from the AttributeCollection. 
    Dim myAttribute As DesignerAttribute = _
        CType(attributes(GetType(DesignerAttribute)), DesignerAttribute)
    Console.WriteLine(("The designer for this class is: " & myAttribute.DesignerTypeName))
    
    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 DesignerAttribute
     * from the AttributeCollection. */
    DesignerAttribute myAttribute = 
       (DesignerAttribute)attributes[typeof(DesignerAttribute)];
    Console.WriteLine("The designer for this class is: " + myAttribute.DesignerTypeName);
  
    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 DesignerAttribute
    * from the AttributeCollection. */
    DesignerAttribute* myAttribute = 
        dynamic_cast<DesignerAttribute*>(attributes->Item[__typeof(DesignerAttribute)]);
    Console::WriteLine(S"The designer for this class is: {0}", myAttribute->DesignerTypeName);

    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

Assembly: System (in System.dll)

See Also

DesignerAttribute Members | System.ComponentModel Namespace | Attribute

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft