Luiscencio
Luiscencio

Reputation: 3965

How do I identify which control generated the Click event?

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)
        }
    }

Upvotes: 1

Views: 1109

Answers (1)

John Saunders
John Saunders

Reputation: 161831

void x_Click(object sender, EventArgs e)
{
    Button who = (Button) sender;
    // you can now access who.Text, etc.
}

Upvotes: 10

Related Questions