C#事件技巧
当多个控件引用同一事件时可以做如下处理
namespace EventForm { public partial class Form1 : Form { public Form1() { InitializeComponent(); //挂接事件处理器方法 button3.Click += ButtonClick; } private void ButtonClick(object sender, EventArgs e) { //判断当前按钮执行事件 if (sender==this.button1) { textBox1.Text = "Button1"; } if (sender==this.button2) { textBox1.Text = "Button2"; } if (sender==this.button3) { textBox1.Text = "Button3"; } } } }
浙公网安备 33010602011771号