One: Attribute Converter (TypeConverter)
1, the form of the drop-down list box:
To use the properties of the drop-down list box. We first want to define an attribute, in this example I define a string type property filename.
Private string _filename;
Public String FileName
{
Get {return this._filename;}
Set {this._filename = value;
}
After defining the property, we have to have a property converter. So what is the property converter? In fact, only the string type can only be identified in the property browser, so we have to convert our attributes into a string through the property converter, but also convert this string to our own after changing this string in the property browser. Attributes. Do you sound some Hu coated? It doesn't matter whether we do a property converter, you will know.
Since the properties used in this example are string types so we have to inherit a new string form in the form of a new string form from system.com. Here is the comment in this code and code, I believe that everyone can understand:
///
/// Extended string converter (realization of the drop-down list box)
/// summary>
Public class filenameconverter: system.componentmodel.stringconverter
{
///
/ / / Determine if the drop-down frame is determined according to the return value
/// summary>
///
/// true: The form of the box
/// false: the form of ordinary text editing
/// returns>
Public override Bool GetStandardValuessupported (System.comPonentmodel.ityped Context)
{
Return True;
}
///
/// Down-pull box specific content
/// summary>
Public override system.componentmodel.typeconverter.standardvaluescollection getStandardValues (System.comPonentModel.ityped "criptorContext Context)
{
Return New StandardValuesCollection (new string [] {"file1.bat", "file2.exe", "file3.dll"});
}
///
// / Determine if it is an in -rable text box according to the return value
/// summary>
///
/// true: Text box cannot be edited
/// Flase: Text box can be edited
/// returns>
Public Override Bool GetStandardValuesexClusive (System.comPonentModel.ityped Context)
{
Return True;
}
Ok, the attribute converter is over, and finally don't forget to specify this property converter to the attribute we have written. The code is as follows:
[CategoryAttribute ("Custom complex type settings (including custom type converters)",
TYPECONVERTERATITRIBUTE (TypeOf (propertyGridapp.FileNameConverter), ReadonlyAttribute (False)]
Public String FileName
{
Get {return this._filename;}
Set {this._filename = value;
}
The program screen after compiling is as follows: