【问题标题】:How do I identify which control generated the Click event?如何识别哪个控件生成了 Click 事件?
【发布时间】:2023-03-25 23:56:01
【问题描述】:

在以下代码中,如何识别引发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)
        }
    }

【问题讨论】:

    标签: c# events controls


    【解决方案1】:
    void x_Click(object sender, EventArgs e)
    {
        Button who = (Button) sender;
        // you can now access who.Text, etc.
    }
    

    【讨论】:

      猜你喜欢
      • 2013-04-08
      • 1970-01-01
      • 2017-09-17
      • 1970-01-01
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多