前一章,我们创建了最简单的组件,今天讲讲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上。
| 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 { } } } } |
关键字 本文所属关键字相关 与本文相关文章分类 所有文章关键字导航源码编程相关Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏 操作系统/服务器相关Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器 标准 网站致力的规范 |