advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
What a great technique! Being able to take advantage of the design-time features of the .NET Framework at runtime, to present users with property editors can certainly simplify development when you need to let users pick a value or choose some other arbitrarily complex values. What do you think of this article? Will you use the GenericValueEditor class or any of the techniques shown in your own applications? Let us know in the .NET Technical forum on DevX
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 4.7/5 | Rate this item | 10 users have rated this item.
 

Build a Property Editor That Can Edit Any .NET Type

This article describes how to create a Windows Forms control that leverages the power of the .NET Framework's UITypeEditor and TypeConverter classes at runtime to create a control that can display and edit the values of all .NET types. 


advertisement
he .NET framework offers a large set of controls for people who are creating Windows Forms applications: the TextField control for editing text, the CheckBox for Boolean values, the ComboBox for choosing a value between a list, and even a DateTimePicker control for selecting dates, among many others. But even this rich control set doesn't cover all the needs of every application. For example, the platform does not provide a simple control for letting users choose a color—and of course there's no control for editing user-defined types. Creating such controls can be very time consuming.


This article explains how to create a Windows Forms control that can edit and represent values of all .NET types, called the GenericValueEditor. It exploits two notions present in the .NET framework: type editors (UITypeEditor) and type converters (TypeConverter). With such a control, programmers can use either the predefined UITypeEditors provided by the framework or custom design-time editors they have developed, and use them in a final application to provide rich runtime editors.

Figures 1-4 show some examples of the types of editor controls that you'll be able to create using the techniques discussed in this article:

 
Figure 1. Color Editor Control: Lets users pick a color from among three different color sets: Custom, Web, or System.
 
Figure 2..NET DashStyle Enumeration Editor: This editor lets users pick a dash style.
 
Figure 3..NET Enum DayOfWeek Editor: This editor lets users pick a day of the week.
 
Figure 4. Font Editor: This editor lets users select a font from among the fonts installed on the system.
All the examples shown in Figures 1-4 are instances of the GenericValueEditor. This article shows and explains important code fragments of the control, but you will need to download the full source code to use the control in your projects.

  Next Page: Design-time Features: UITypeEditor and TypeConverter


Page 1: IntroductionPage 5: Changing the Edited Value
Page 2: Design-time Features: UITypeEditor and TypeConverterPage 6: Dropping the UITypeEditor
Page 3: Implementing the GenericValueEditorPage 7: Implementing the IWindowsFormsEditorService Interface
Page 4: Defining the Edited Type, UITypeEditor, and TypeConverter 
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs