How can I subscribe multiple buttons to the same event handler and act according to what button was clicked?

Viewed 65406

I have 6 buttons that I want to be attached to the same handler. How can I do this?

9 Answers

 button1.Click += button_Click;
 button2.Click += button_Click;

void button_Click(object sender, EventArgs e)
        {
            if (sender == button1)
            {
                this.Text = "1";
            }
            else if (sender == button2)
            {
                this.Text = "2";
            }
        }

Related