Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
DesignerAttribute Class

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

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)
Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Interface, AllowMultiple := True,  _
    Inherited := True)> _
Public NotInheritable Class DesignerAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As DesignerAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Interface, AllowMultiple = true, 
    Inherited = true)]
public sealed class DesignerAttribute : Attribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Interface, AllowMultiple = true, 
    Inherited = true)]
public ref class DesignerAttribute sealed : public Attribute
JScript
public final class DesignerAttribute extends Attribute

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.

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

Visual C++
[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Windows.Forms.Design.DLL",
IRootDesigner::typeid),
DesignerCategory("Form")]
ref class MyForm: public ContainerControl{
   // Insert code here.
};

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

Visual C++
int main()
{
   // Creates a new form.
   MyForm^ myNewForm = gcnew 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[ DesignerAttribute::typeid ]);
   Console::WriteLine( "The designer for this class is: {0}", myAttribute->DesignerTypeName );
   return 0;
}

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Using DesignerAttribute in Compact Framework      dvboom   |   Edit   |   Show History
Compact Framework's System.ComponentModel namespace does not contain DesignerAttribute. In order to add this and other design-time attributes, you must add a "Design-Time Attribute File" (right-click on the project, Add-->New Item, in Windows Forms, select "Design-Time Attribute File"). This is an XML file with an .xtma extension. Using the Intellisense that's provided, you can see that you can add a Class tag and name the class you'd like to add the attribute to. Inside of that, further Intellisense will tell you that Designer is an available XML node. You will need to supply the Type as well as the BaseType (not sure why this is necessary, since base types can be determined through reflection), with fully qualified assembly names. Here is an example of what that looks like:

<?xml version="1.0" encoding="utf-16"?>
<Classes xmlns="http://schemas.microsoft.com/VisualStudio/2004/03/SmartDevices/XMTA.xsd">
  <Class Name="DeviceControlsLibrary.DeadlyControl">
    <Designer>
      <Type>DeviceControlDesignersLibrary.DeadlyControlDesigner, DeviceControlDesignersLibrary,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</Type>
      <BaseType>System.ComponentModel.Design.IDesigner, System, Version=2.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089</BaseType>
    </Designer>
  </Class>
</Classes>

The <Type> tag is your control's type (with namespace), followed by the fully qualified assembly name. The BaseType should be used as shown here.

You can find more information on this topic in this article: http://dvanderboom.wordpress.com/2008/03/14/compact-framework-creating-custom-controls-and-designers-part-1/
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker