国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

深入淺出組件編程之固有屬性和事件屬性

2024-07-21 02:29:33
字體:
來源:轉載
供稿:網(wǎng)友
中國最大的web開發(fā)資源網(wǎng)站及技術社區(qū),
  前一章,我們創(chuàng)建了最簡單的組件,今天講講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窗口如下:




  我原來沒有用過defaultvalueattribute,上面代碼中的address、age在customer1創(chuàng)建時沒有得到defaultvalue,我會找出原因,并在下章補上,也希望知道的朋友能告之。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 罗甸县| 大宁县| 伊春市| 开阳县| 兴文县| 呼和浩特市| 祁门县| 湖北省| 读书| 江川县| 罗城| 武功县| 舞钢市| 沭阳县| 丰宁| 马龙县| 遂昌县| 山丹县| 海南省| 若尔盖县| 舞钢市| 南阳市| 洪洞县| 普兰店市| 万载县| 璧山县| 响水县| 阿拉尔市| 韩城市| 黄骅市| 平陆县| 宣威市| 宁蒗| 福州市| 疏勒县| 弥勒县| 通山县| 南康市| 桐城市| 屏东县| 沅陵县|