深入浅出组件编程之固有属性和事件属性
发布时间:2006-03-10 13:57:48 来源:BLOG 网友评论 0 条 前一章,我们创建了最简单的组件,今天讲讲Component的PropertyAttribute和EventAttribute。
EventAttribute有:
BrowsableAttribute 、CategoryAttribute、DescriptionAttribute、DefaultEventAttribute
PropertyAttribute有:
BrowsableAttribute 、CategoryAttribute、DescriptionAttribute、DefaultPropertyAttribute、DefaultValueAttribute、EditorAttribute、DesignerSerializationVisibilityAttribute、TypeConverterAttribute、BindableAttribute、LocalizableAttribute
在本章教程中我们主要讲以上红色的Attribute,再下章的Designer UI会讲蓝色的Attribute,紫色的Attribute不作讲解。
上述的Attribute简明阐述如下:
BrowsableAttribute:在Property窗口中是否可见。
CategoryAttribute:Property或者Event所属的哪个组。
DescriptionAttribute:Property或者Event的简单描述。
DefaultEventAttribute:默认Event。
DefaultPropertyAttribute:默认Property,选中组件,其Property窗口中默认选中在这个Property上。
DefaultValueAttribute:Property的默认值,选中组件,其Event窗口中默认选中在这个Event上。
其Property、Event窗口如下:
我原来没有用过DefaultValueAttribute,上面代码中的Address、Age在Customer1创建时没有得到DefaultValue,我会找出原因,并在下章补上,也希望知道的朋友能告之。
EventAttribute有:
BrowsableAttribute 、CategoryAttribute、DescriptionAttribute、DefaultEventAttribute
PropertyAttribute有:
BrowsableAttribute 、CategoryAttribute、DescriptionAttribute、DefaultPropertyAttribute、DefaultValueAttribute、EditorAttribute、DesignerSerializationVisibilityAttribute、TypeConverterAttribute、BindableAttribute、LocalizableAttribute
在本章教程中我们主要讲以上红色的Attribute,再下章的Designer UI会讲蓝色的Attribute,紫色的Attribute不作讲解。
上述的Attribute简明阐述如下:
BrowsableAttribute:在Property窗口中是否可见。
CategoryAttribute:Property或者Event所属的哪个组。
DescriptionAttribute:Property或者Event的简单描述。
DefaultEventAttribute:默认Event。
DefaultPropertyAttribute:默认Property,选中组件,其Property窗口中默认选中在这个Property上。
DefaultValueAttribute:Property的默认值,选中组件,其Event窗口中默认选中在这个Event上。
| using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; namespace Components { // PropertyAttribute、EventAttribute分别放在Property、Event上,并[]括起来。 // DefaultPropertyAttribute、DefaultEventAttribute必须放在类头上。 [DefaultEvent("CustomerLogout")] public class Customer : Component { private string _id; private string _sex; private int _age; private string _address; private DateTime _createTime; // 没有CategoryAttribute、DescriptionAttribute。 public string Id { get { return _id; } set { _id = value; } } // 此属性在Customer's Details分组中,CategoryAttribute、DescriptionAttribute也适用于Event。 [Category("Customer's Details"), Description("Customer's Sex")] // 可以在一个[]里写两个Attribute。 public string Sex { get { return _sex; } set { _sex = value; } } [Category("Customer's Details")] [Description("Customer's Age"), DefaultValue(20)] public int Age { get { return _age; } set { _age = value; } } [DefaultValue("shanghai"),Category("Customer's Details")] public string Address { get { return _address; } set { _address = value; } } [Browsable(false)] // 此Property在Property窗口中不可见,BrowsableAttribute也适用于Event。 public DateTime CreateTime { get { return _createTime; } set { _createTime = value; } } public sealed class CustomerLoginEventArgs : EventArgs { } public sealed class CustomerLogoutEventArgs : EventArgs { } public delegate void CustomerLoginEventHandler(object sender, CustomerLoginEventArgs e); public delegate void CustomerLogoutEventHandler(object sender, CustomerLogoutEventArgs e); public event CustomerLoginEventHandler CustomerLogin { add { } remove { } } public event CustomerLogoutEventHandler CustomerLogout { add { } remove { } } } } |
其Property、Event窗口如下:
![]() ![]() |
我原来没有用过DefaultValueAttribute,上面代码中的Address、Age在Customer1创建时没有得到DefaultValue,我会找出原因,并在下章补上,也希望知道的朋友能告之。
- 推荐阅讯
- Spring框架的事务管理应用分析
- Oracle数据库的安全策略
- J2ME手机游戏引擎程序结构简述
- 在J2ME中基于MIDP1.0实现组合按键
- web2.0—使媒体开始重建秩序
- Thinking in AJAX(三)——AJAX框架汇总
- Spring入门指引之理解Spring的打包方式
- WEB2.0教程:什么是SNS网站?
- Opera 9.0首个公开Beta版发布
- 看看如何在Struts应用中施展AJAX魔法
- 阅读排行
- 1..net页面间的参数传递简单实例
- 2.VC++与Matlab混合编程之引擎操作详解
- 3.Oracle数据库数据对象分析
- 4.Eclipse3.2+Tomcat5.5.17+Oracle9配置
- 5.Oracle数据库中索引的维护
- 6.在Oracle的网络结构中解决连接问题
- 7.Oracle数据安全面面观
- 8.Oracle数据库的ORA-00257故障解决过程
- 9.Oracle数据库备份与恢复的三种方法
- 10.Oracle与SQL Server在企业应用中的比较
- 专题教程
- Windows Server-Windows Server文档-Windows Server新闻-Windows Ser PostgreSQL-PostgreSQL文档-PostgreSQL新闻-PostgreSQL专家
- WebLogic-WebLogic文档-WebLogic新闻-WebLogic专家 FreeBSD-FreeBSD文档-FreeBSD新闻-FreeBSD专家
- Linux-内核 GUI KDE Gnome DNS FTP 安全 安装-Linux专区 Windows-AD IIS ServerCore 虚拟化 安全 HPC-Windows专区
- 大话G游 专题:手机病毒揭密
- ARP攻击防范与解决方案 路由故障处理手册


