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

首頁 > 開發 > 綜合 > 正文

關于事件處理(C#)

2024-07-21 02:22:22
字體:
來源:轉載
供稿:網友
者來說,不必關心委托的細節,就像上面的例子一樣,簡單的實現了事件.
2.windows forms
例子中,有一個butto和一個textbox,當點擊按鈕時,文本框,改變背景顏色.
using system;
using system.componentmodel;
using system.windows.forms;
using system.drawing;
public class myform : form
{  
   private textbox box;
   private button button;
   
   public myform() : base()
   {  
      box = new textbox();
      box.backcolor = system.drawing.color.cyan;
      box.size = new size(100,100);
      box.location = new point(50,50);
      box.text = "hello";
      
      button = new button();
      button.location = new point(50,100);
      button.text = "click me";
      
      //為了關連事件,生成一個委托實例同時增加它給click事件.
      button.click += new eventhandler(this.button_clicked);
      controls.add(box);
      controls.add(button);   
   }
   //事件處理器
   private void button_clicked(object sender, eventargs e)
   {
      box.backcolor = system.drawing.color.green;
   }
   // stathreadattribute說明windows forms使用單線程套間模型.
   [stathreadattribute]
   public static void main(string[] args)
   {
      application.run(new myform());
   }  
}
保存"events.cs",在命令行中輸入,以下
  csc /r:system.dll,system.drawing.dll,system.windows.forms.dll events.cs
編譯生成,events.exe,執行,可看到效果.
上面的例子,簡單的說明了.net中,事件的處理.一個事件,必須有事件源,和事件數據.在例子中,事件數據用evengargs.它是所有事件數據類的基類.
為了更好的理解事件.可以去msdn中看關于,事件和委托的教程.
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吉林省| 海淀区| 岑溪市| 托克逊县| 鹤庆县| 安新县| 平罗县| 萨嘎县| 吉安县| 云林县| 黄冈市| 延吉市| 阜南县| 邵阳市| 武邑县| 通河县| 贞丰县| 多伦县| 宜城市| 西充县| 图木舒克市| 鄂州市| 肥乡县| 涞水县| 五家渠市| 石城县| 四川省| 大冶市| 哈巴河县| 鄂托克旗| 辽阳县| 鄂温| 高雄县| 宁城县| 梁山县| 莱西市| 太保市| 营口市| 固阳县| 瑞丽市| 乐山市|