1、在事件处理程序中,声明类型与引发事件的控件匹配的变量。将 2、事件处理程序的 sender 参数分配给变量,将它强制转换为适当的类型。下面的示例演示由几个不同按钮调用的 void Button_Click(object sender, System.EventArgs e) { Button b; b = (Button)sender; switch (b.ID) { case "Button1": Label1.Text = "You clicked the first button"; break; case "Button2": Label1.Text = "You clicked the second button"; break; case "Button3": Label1.Text = "You clicked the third button"; break; } } 相关文章: