Tuesday, May 09, 2006

Creating a Custom .NET Property Editor

This How To explains how to create a custom editor for a property who's class cannot be edited by one of the built in VisualStudio Property Page editors.

In general, a public property can be modified "at Design Time" by using Visual Stuio .NET's Property Page. Concider the following component:

public class MyComponent : Component
{
private string myString;
public string MyString
{
get { return myString; }
set { myString = value; }
}
}

Concider also that this component MyComponent were added to a user control, say MyControl. Using the Visual Studio control designer an instance of the component would appear at the bottom of the designer window.

When designing a control, the user may manually set the values of properties of the components and controls contained in the control being designed. This is done by right clicking on a component or control, say MyComponent, and and selecting Properties. The Property Page window will show all the public properties for the control.

In our case, the Property Page would show MyString and the user could then proceed to edit the property's value simply by entering a value next to the entry int the Property Page.

0 Comments:

Post a Comment

<< Home