event & delegate Demo(事件&委托示例)
1 using System; 2 using System.ComponentModel; 3 using System.Windows.Forms; 4 5 namespace WindowsFormsApplication1 6 { 7 public partial class Form1 : Form 8 { 9 public delegate void ActionEventHandler( object sender, ActionCancelEventArgs ev); // 声明一个delegate 10 public static event ActionEventHandler Action; // 声明一个名为Action的事件 11 12 string _time = "" ; 13 14 public Form1() 15 { 16 InitializeComponent(); 17 Form1.Action += new ActionEventHandler(Form1_Action); // 为事件Action增加处理程序(即通过ActionEventHandler这个delegate来调用Form1_Action) 18 } 19 20 private void Form1_Action( object sender,