按钮单击检查? [英] button click check ?

查看:67
本文介绍了按钮单击检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找出是否有办法
检查是否单击了一组按钮
对于exp.如果我有九个按钮并且要检查
看看是否点击了这九个按钮中的任何一个,如if(button1.text =="
button2.text =="
button3.text =="
button4.text =="
button5.text ==")
因此,我们无需检查每个单独的点击,而只需检查
nomatter单击了什么按钮????

I WANT to find out if a there is a way
to check if a group of buttons are being clicked
for exp. if i have nine buttons and i want to check
to see if any of the nine is clicked like if(button1.text ==""
button2.text ==""
button3.text==""
button4.text==""
button5.text=="" )
so instead of checking each Individual click we can have it check
nomatter what button is clicked????

推荐答案

所有错误.您无需检查任何内容.此类事物的编程是面向事件的.您需要处理 click事件:

All wrong. You don''t need to check anything. The programming of such things is event-oriented. You need to handle the click event:

myButton.Click += (sender, eventArgs) => {
   Button senderButton = (Button)sender; // here you know the reference to a particular button
   // do something specific to this button
   // for example:
   ButtonSpecificCode(senderButton); // here you can use some properties of clicked button
};

// so, if you add identical handler to a set of buttons, you can still operate the reference to a specific one:
foreach(Button button in new Button[] { myFirstButton, mySecondButton, anotherOne, /* ... */ })
    button.Click += (sender, eventArgs) => { /* ... */ };



如果原则上仍不清楚,这可能是有用的提示:
http://en.wikipedia.org/wiki/Inversion_of_control [

—SA



If this is still not clear in principle, this could be a useful hint:
http://en.wikipedia.org/wiki/Inversion_of_control[^].

Actually, the whole thinking of "click check" should be inverted. :-)

—SA


这篇关于按钮单击检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆