我如何确定哪些控件生成的Click事件? [英] How do I identify which control generated the Click event?
本文介绍了我如何确定哪些控件生成的Click事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的代码,我怎么确定哪些控件引发的点击
事件?
无效x_Click(对象发件人,EventArgs五)
{
//我如何识别发送者?
}
私人空隙填充()
{
的(废话)
{
键X =新的Button();
x.Click + =新的EventHandler(x_Click);
this.controls.Add(X)
}
}
解决方案
无效x_Click(对象发件人,EventArgs五)
{
键谁=(按钮)发送;
//您现在可以访问who.Text等
}
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)
}
}
解决方案
void x_Click(object sender, EventArgs e)
{
Button who = (Button) sender;
// you can now access who.Text, etc.
}
这篇关于我如何确定哪些控件生成的Click事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文