4. C# 中事件的實現
首先,我先構建一個使用者控制項專案,程式碼如下:
namespace Ctrleven
{
public partial class UserControl1 : UserControl
{
// 定義委派
public delegate void MyEventHander();
// 用委派宣告事件
public event MyEventHander MyEvent;
public UserControl1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MyEvent();
}
}
}