如何访问单击的按钮?

时间:2013-11-28 15:59:59

标签: c# button

我在jQuery中有代码:

// Group of buttons
$(".buttons").click(function() {

    // Do something with one button
    $(this). ...

});

我在C#Window Forms中有另一个程序:

private void someButtons_Click(object sender, EventArgs e) {

    // How to know which button was clicked?
    // How to get an instance of that button?

}

非常感谢!

2 个答案:

答案 0 :(得分:2)

你的意思是

private void someButtons_Click(object sender, EventArgs e) {
  var button = (Button)sender;
}

答案 1 :(得分:1)

   private void someButtons_Click(object sender, EventArgs e)
    {
        // How to get an instance of that button?
        Button myButton = ((Button)sender);

        // How to know which button was clicked?
        string buttonId = myButton.ID;
    }