选择显示字体大小

深入浅出组件编程之固有属性和事件属性


  前一章,我们创建了最简单的组件,今天讲讲component的propertyattribute和eventattribute。

  eventattribute有:

  browsableattribute 、categoryattribute、descriptionattribute、defaulteventattribute

  propertyattribute有:

  browsableattribute 、categoryattribute、descriptionattribute、defaultpropertyattribute、defaultvalueattributeeditorattribute、designerserializationvisibilityattribute、typeconverterattributebindableattribute、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窗口如下:


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

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   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范