Custom Controls Design Time Support Part 7: UITypeEditor Introduction

In the previous posts in this series I introduced how to use some basic and advanced Attributes and how to add an image for your control to appear in the toolbox and then I gave an introduction on TypeConverters and examples here and here on how to use the TypeConverters. Now I will give an introduction on how UITypeEditors used in design time.

First, what is a UITypeEditor anyway from MSDN :

The UITypeEditor class provides a base class that you can derive from and extend to implement a custom type editor for the design-time environment. Typically, your custom type editor interacts with the PropertyGrid control.


So the UITypeEditor interacts with the PropertyGrid where does it appear?? It appears in the left hand side of the property or just the value of the property in the PropertyWindow.

Any examples ?? yes there are multiple built in UITypeEditors for a lot types, one example is the FontEditor, when you edit any property of type Font you find by default a button ellipses like this .

Another example is the ColorEditor, while trying to get a screen shot for the color editor I found something interesting, in Visual Studio 2005 is different than that in Visual Studio 2008 more over in VS 2008 the color editor used with Web Controls is different than that used with windows controls.

Visual Studio 2005 Version

Visual Studio 2008 Windows Version

Visual Studio 2008 Web Version


Exploring the System.Drawing.Design.UITypeEditor methods.

GetEditStyle  Gets the editor style used by the EditValue method.
EditValue  Edits the value of the specified object using the editor style indicated by the GetEditStyle method.
GetPaintSupported  Indicates whether this editor supports painting a representation of an object's value.
PaintValue  Paints a representation of the value of an object using the specified PaintValueEventArgs.

The property.

 IsDropDownResizable  Gets a value indicating whether drop-down editors should be resizable by the user.

So, from the above pictures, the methods and the single property we can guess what a UITypeEditor can let us do.

  1. The editor can have one of three styles
    1. Modal -> a popup window as the FontEditor.
    2. DropDown -> a dropdown form as the VS2005 ColorEditor.
    3. None -> neither Modal nor DropDown just text as the Name property. (default Style for all Properties)
  2. You can draw anything within the small rectangle beside the property value (e.g. ColorEditor draws a solid rectangle with the chosen color beside it).
  3. When using the DropDown style you can make it resizable or not (e.g the VS2008 Windows ColorEditor is Resizable while the 2005 is not resizable).

Well thats enough for a fast introduction next part I'll give an example or two on how to implement an Editor from scratch, may be a new ColorEditor too.Smile







Leave a Reply

Your email address will not be published. Required fields are marked *