一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

自定义组件之属性(Property)的性质(Attribute)介绍(四)

时间:2008-01-12 编辑:简简单单 来源:一聚教程网

二:UI属性编辑器(UITypeEditor)
这里的属性编辑器的意思是能够实现上面提到的弹出对话框和下拉UI的形式。废话不说下面我们一一介绍。
1、 弹出对话框的形式
在本例中我使用了string类型的属性来显示版本的信息,大家可以随便的写各类的属性,这里只需要指定改属性的编辑器就可以了。
首先我们要建立一个string类型的属性,代码如下:
private string _appVer="1.0";

[CategoryAttribute("自定义编辑器"),
DefaultValueAttribute("1.0"),
DescriptionAttribute("版本信息"),
ReadOnlyAttribute(true),
EditorAttribute(typeof(AppVerConverter),typeof(System.Drawing.Design.UITypeEditor))]
public string AppVer
{
get {return this._appVer;}
set {this._appVer=value;}
}
大家可能已经注意到了在这个属性之多出了一个性质EditorAttribute(typeof(AppVerConverter),typeof(System.Drawing.Design.UITypeEditor)),具体的意思大家可以参考MSDN我在这里就不用多说了,那么我们看看AppVerConverter这个类是怎么实现的就可以了。具体代码如下:
///
/// 自定义UI的属性编辑器(弹出消息)
///

public class AppVerConverter:System.Drawing.Design.UITypeEditor
{
///
/// 覆盖此方法以返回编辑器的类型。
///

public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)

热门栏目