views:

119

answers:

1

In the following code, how do I identify which control raised the Click event?

    void x_Click(object sender, EventArgs e)
    {
        //How do I identify the sender?
    }

    private void fill()
    {
        for(blah)
        {
            Button x = new Button();
            x.Click += new EventHandler(x_Click);
            this.controls.Add(x)
        }
    }
+9  A: 
void x_Click(object sender, EventArgs e)
{
    Button who = (Button) sender;
    // you can now access who.Text, etc.
}
John Saunders
thank you very much
Luiscencio