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();
}
}
}