Browse DevX
Sign up for e-mail newsletters from DevX


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.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date