public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("ok");
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Click+=new EventHandler(button1_Click);
button2.Enter += new EventHandler(ShowText);
button2.KeyUp += new KeyEventHandler(testEvent);
}
public void ShowText(object send = null, EventArgs f = null)
{
MessageBox.Show("show!!!");
}
public void testEvent(object send, KeyEventArgs e)
{
MessageBox.Show("test");
}
}
在试图设计器中,没有直接中属性中双击生成事件,而是手动添加及绑定事件,需要注意的一点是,以button2的Enter事件为例,见图片:
button2.KeyUp += new KeyEventHandler(testEvent);