如何识别哪些控件生成的Click事件?(How do I identify which contro

2019-08-17 04:28发布

在下面的代码,我怎么确定哪些控件引发的Click事件?

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

Answer 1:

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


文章来源: How do I identify which control generated the Click event?