public partial class Form1 : Form
{
public event EventHandler BossEventHandler; //處理事件的物件
public class BossEventArgs : EventArgs //傳送物件的資訊
{
public string Message { get; set; }
}
//public void OnEventCall(BossEventArgs e)
//{
// //通知執行所有已註冊在Boss類別的EventHandler的方法
// BossEventHandler(this, e);
//}
public Form1()
{
InitializeComponent();
BossEventHandler += new EventHandler(this.button2_Click);
BossEventHandler += new EventHandler(this.button3_Click);
}
private void button1_Click(object sender, EventArgs e)
{
BossEventHandler(this, e); //觸發事件
textBox1.Text += "已按下Button1";
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text += "已按下Button2";
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text += "已按下Button3";
}
}
=============================================================================
Result =
已按下Button2已按下Button3已按下Button1
留言列表