none
How can I see which component is, using "sender" on onClick method RRS feed

  • Question

  • I would like to use only one OnClick() for all my buttons in a windows form.

    How can I see which button has been pressed base on "sender" object inside of the onclick method?

    thanks in advance for your help,

    Edward
    Wednesday, November 15, 2006 12:04 AM

All replies

  • cast the sender parameter to Button type and you can see the Name, Text property which will tell you which button is clicked.

    private void buttons_Click(object sender, EventArgs e)
    {
        Button clickedButton = (Button)sender;
        MessageBox.Show(clickedButton.Text + " clicked!");
    }
    Wednesday, November 15, 2006 12:17 AM