Write the RAD component that interacts with the. NET property window (IV)

Source: Internet
Author: User
Tags string format
VII. Custom types for writing and displaying
There are three ways to edit the attribute window: 1. In some cases, you can edit the window as a string, and type conversion is implemented by TypeConverter. 2. You can select a value from the drop-down list. 3. An omitted button provides other UI interfaces for editing values, such as FileDialog and FontPicker. We have already talked about the string format. Next we will look at the drop-down list.
. NET framework already contains several examples of drop-down lists, such as Color, AccessibleRole, and Dock. The following figure shows the implementation of the drop-down list.
Figure 4. Drop-down list editor
The implementation of the drop-down is also defined by TypeConverter. If you look at the description of TypeConverter, you can see that there are three virtual functions to implement this function: GetStandardValuesSupported (), GetStandardValues () and GetStandardValuesExclusive (). To reload these methods, we can provide a pre-defined value list for the attribute. In fact, TypeConverter implements the enumerated values in the drop-down list. The property window itself does not have code to edit the drop-down list, but only uses the TypeConverter method.
For example, we have a FamilyMember component that contains the Relation attribute, allowing users to select the relationship between them and others. To make the interface more user-friendly during design, the attribute window should use a drop-down list to provide some common values, such as mother, father, daughter, and sister. In addition to common values, component users can also enter other string values that represent links.
Public class FamilyMember: Component
{
Private string relation = "Unknown ";
[TypeConverter (typeof (RelationConverter), Category ("Details")]
Public string Relation
{
Get {return relation ;}
Set {this. relation = value ;}
}
}

Internal class RelationConverter: StringConverter
{
Private static StandardValuesCollection defaultRelations =

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.