国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 保定市| 江西省| 二连浩特市| 西丰县| 冀州市| 广宁县| 萍乡市| 乡城县| 长葛市| 衡东县| 德州市| 内乡县| 广德县| 肇东市| 绥阳县| 东阳市| 昭苏县| 安达市| 江陵县| 岗巴县| 晋中市| 龙海市| 钟祥市| 大丰市| 孝感市| 永嘉县| 汽车| 贵州省| 阿合奇县| 徐水县| 潢川县| 临汾市| 新源县| 依兰县| 渝北区| 正定县| 和顺县| 安达市| 阿克| 双城市| 沂水县|