Home arrow C# arrow Page 5 - Custom Controls and Design-Time Support: Part 2/2

Custom Controls and Design-Time Support: Part 2/2

Creating custom controls is a key technique in .NET development. This article by Matthew is the second of a two part series where he looks at how to create a custom Windows Form control that behaves properly in Visual Studio .NET.

Author Info:
By: Wrox Team
Rating: 4 stars4 stars4 stars4 stars4 stars / 25
January 13, 2003
  1. · Custom Controls and Design-Time Support: Part 2/2
  2. · The DirectoryTree
  3. · Filtering Control Class Members
  4. · Designer Verbs
  5. · UITypeEditors
  6. · Custom UITypeEditors
  7. · Conclusion

print this article

Custom Controls and Design-Time Support: Part 2/2 - UITypeEditors
(Page 5 of 7 )

The Properties window does a solid job of providing support for all common data types. Basic data types like strings and numbers are all seamlessly supported. If you create a property that uses a custom enumeration, the Properties window automatically provides a drop-down list with the values from the enumeration.

In addition to this basic level of support, you may have noticed that some richer object types have additional design-time support.

For example, if you create a Property that has a Font or Color data type, a special color picker or font selection dialog will be used in the Properties window. Similar magic happens if you create a Collection property.

This support is provided through .NET UITypeEditor classes, which are special components that provide the design-time user interface that allows the programmer to set complex properties.

Prebuilt UITypeEditors

The base UITypeEditor class is found in the System.Drawing.Design namespace. You can inherit from this class to create your own custom UITypeEditors, or you can use one of the derived classes that are provided with the .NET framework.

These classes are listed below (UITypeEditors that are only usable with specific web controls have been omitted-see MSDN for more information about those).

System.ComponentModel.Design.ArrayEditorEdits an array by allowing the programmer to enter a list of strings. Used automatically for supported arrays.

Allows the programmer to select and configure a font. Used automatically for font properties.
System.Drawing.Design.ImageEditorAllows the programmer to create an Image object by selecting a bitmap from an open file dialog. Used automatically for image types.
System.Web.UI.Design.WebControls.RegexTypeEditorAllows the programmer to choose a regular expression from a list of common choices. This UITypeEditor works with string properties.
System.Windows.Forms.Design.AnchorEditorAllows the Anchor property to be set at design time.
System.Windows.Forms.Design.FileNameEditorAllows a fully qualified filename to be set by choosing a file from an open file dialog box. This UITypeEditor works with string properties.

Depending on the data type of your property, .NET may use the corresponding UITypeEditor automatically (for example, with a Font).

On the other hand, some UITypeEditors do not have dedicated types. An example is the RegExTypeEditor, which allows the programmer to choose a common regular expression for a control property. The regular expression is stored as an ordinary string, so it needs to be explicitly associated with the appropriate UITypeEditor.
blog comments powered by Disqus

- Introduction to Objects and Classes in C#, P...
- Visual C#.NET, Part 1: Introduction to Progr...
- C# - An Introduction
- Hotmail Exposed: Access Hotmail using C#
- Razor Sharp C#
- Introduction to Objects and Classes in C#
- Making Your Code CLS Compliant
- Programming with MySQL and .NET Technologies
- Socket Programming in C# - Part II
- Socket Programming in C# - Part I
- Creational Patterns in C#
- Type Conversions
- Creating Custom Delegates and Events in C#
- Inheritance and Polymorphism
- Understanding Properties in C#

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials