我創建運行時2個按鈕,我需要做的事情不同,這取決於哪個按鈕點擊,獲取價值的WinForms
下面是代碼,我已經爲click事件編寫的,但是我不知道我該如何編碼我的程序瞭解哪個按鈕被點擊的位置。
{
.
.
Button btn = new Button();
btn.Location = new Point(x+70,y);
btn.Height = 15;
btn.Width = 50;
Controls.Add(btn);
btn.Name = "button1";
btn.Click +=btn_Click;
btn = new Button();
btn.Location = new Point(x + 140, y);
btn.Height = 15;
btn.Width = 50;
Controls.Add(btn);
btn.Name = "button2";
btn.Click += btn_Click;
}
private void btn_Click(object sender, EventArgs e)
{
// Understand which of the buttons is clicked!
}
任何幫助表示讚賞。
+1!真棒,謝謝你的幫助! :) – vin