Winform如何獲取當前單擊的控件名稱,比如有100個Button 和一個button_Click()的按鈕事件 ,分別點擊不同按鈕后顯示所點擊的按鈕名稱?
private void button_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
MessageBox.Show(button.Name);
}
然后將要實現的按鈕綁定該button_Click事件。
向窗體添加控件,比如添加一個Button按鈕:
Button abc = new Button();
abc.Location = new System.Drawing.Point(200, 200);
abc.Size = new System.Drawing.Size(100, 100);
//abc.BackColor = Color.Red;
abc.Text = "123456789";
this.Controls.Add(abc);//調用添加方法