Introduction to attributes of custom components (IV)
Source: Internet
Author: User
II. UI property editor (UITypeEditor)
The attribute editor can implement the pop-up dialog box and drop-down UI mentioned above. Let's talk about it one by one.
1. Pop-up dialog box
In this example, I used the string type attribute to display the version information. You can write all kinds of attributes at will. Here, you only need to specify the attribute editing editor.
First, we need to create a string type attribute. The code is as follows:
Private string _ appVer = "1.0 ";
[CategoryAttribute ("custom editor "),
DefaultValueAttribute ("1.0 "),
DescriptionAttribute ("version information "),
ReadOnlyAttribute (true ),
EditorAttribute (typeof (AppVerConverter), typeof (System. Drawing. Design. UITypeEditor)]
Public string AppVer
{
Get {return this. _ appVer ;}
Set {this. _ appVer = value ;}
}
You may have noticed that there is an additional EditorAttribute (typeof (AppVerConverter), typeof (System. drawing. design. UITypeEditor). For more information, see MSDN. I don't need to talk about it here. Let's take a look at how the AppVerConverter class is implemented. The code is as follows:
/// <Summary>
/// Custom UI property editor (pop-up message)
/// </Summary>
Public class AppVerConverter: System. Drawing. Design. UITypeEditor
{
/// <Summary>
/// Override this method to return the editor type.
/// </Summary>
Public override System. Drawing. Design. UITypeEditorEditStyle GetEditStyle (System. ComponentModel. ITypeDescriptorContext context)
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