C#窗体编程学习汇总
程序员文章站
2022-06-10 10:57:08
...
手动添加事件
public Form1()
{
InitializeComponent();
testButton.Click += new EventHandler(this.OnTest);
button1.Click += new EventHandler(this.OnTest);
button1.Name = "button1";
testButton.Name = "hhh";
}
public void OnTest(object sender, EventArgs e)
{
Button btn = sender as Button;
MessageBox.Show($"大家好 {btn.Name} ");
}