
Applying a Type Converter, UI Type Editor, or Designer Attribute
To associate a design-time support provider with a type or type member, apply the appropriate type of attribute on the line above the class declaration or member declaration. The following code example shows a TypeConverterAttribute applied to a type.
<TypeConverter(GetType(MyColorConverter)), _
Editor(GetType(MyColorEditor), GetType(UITypeEditor))> _
Structure MyColor
...
End Structure
[ TypeConverter(typeof(MyColorConverter))]
[ Editor(typeof(MyColorEditor), typeof(UITypeEditor))]
struct MyColor {...}
If the type of a property does not have a type converter or UI type editor associated with it, or if you want to override the default type converter or UI type editor associated with the type of a property, you can apply an attribute to the property itself. To associate a type converter with a property, apply a TypeConverterAttribute to the property declaration, as shown in the following code example.
<TypeConverter(GetType(PointConverter))> _
Public Property MyLocation() As Point
...
End Property
[ TypeConverter(typeof(PointConverter))]
public Point MyLocation {...}
To associate a UI type editor with a property, apply an EditorAttribute to the property, as shown in the following code example.
<Editor(GetType(FlashTrackBarDarkenByEditor), _
GetType(UITypeEditor))> _
Public Property DarkenBy() As Byte
...
End Property
[ Editor(typeof(FlashTrackBarDarkenByEditor), typeof(UITypeEditor))]
public byte DarkenBy {...}
A designer can be associated with a type, but not a property. To associate a designer with a type, apply a DesignerAttribute directly above the class declaration, as shown in the following code example.
<Designer(GetType(HelpLabel.HelpLabelDesigner))> _
Public Class HelpLabel
Inherits System.Windows.Forms.Control
Implements System.ComponentModel.IExtenderProvider
...
End Class
[Designer(typeof(HelpLabel.HelpLabelDesigner))]
public class HelpLabel : System.Windows.Forms.Control, System.ComponentModel.IExtenderProvider {...}
Note: |
|---|
In the above examples, the constructors for the
TypeConverterAttribute,EditorAttribute, and DesignerAttribute classes accept System..::.Type objects as their arguments. This form of constructor for these attributes works if the type is in the same assembly as the design-time classes. If the design-time classes are in a different assembly, then a different form of the attribute constructor (called the assembly-qualified format) is needed, as shown in the following code example.
|
<Designer("System.Windows.Forms.Design.DocumentDesigner, System.Design")> _
Public Class MyForm
Inherits Form
...
End Class
[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Design")]
public class MyForm : Form {...}