如何将布尔值绑定到c#中的按钮? [英] How can I bind a boolean value to a button in c#?

查看:208
本文介绍了如何将布尔值绑定到c#中的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有一个外部按钮,并在定时器中断内读取此按钮的状态,

所以我有一个布尔值。现在我想使用这个布尔值,如System.Windows.Forms.Button或更好的鼠标按钮,点击此按钮。

然后我可以使用按钮事件,如Click,DoubleClick, MouseUp,MouseDown等等。

有没有人知道我该怎么做?

感谢您的帮助!

Hello,

I have an external push button and read the state of this push button within a timer interupt,
so I have a boolean value. Now I would like to use this boolean value like a System.Windows.Forms.Button or better as the mouse button which clicks this Button.
Then I could use the button events such as Click, DoubleClick, MouseUp, MouseDown and so on.
Does anyone have an idea how I can do this?
Thanks for any help!

推荐答案

很抱歉,如果我的答案不符合您的期望,但可能是因为您的问题表达完全混乱 - 请参阅问题的评论。



如果我理解你的想法,你想要一个控件来携带一个布尔值。是这样,这是一个 CheckBox

http://msdn.microsoft.com/en-us/library/system.windows.forms.checkbox%28v=vs.110%29 .aspx [ ^ ]。



是的,您可以直观地将其表示为按钮。在此状态下按下按钮表示True,按钮按下时按False表示。方法如下:您可以使用此属性控制 CheckBox.Appearance

http://msdn.microsoft.com/en-us/library/system.windows.forms.checkbox .appearance%28v = vs.110%29.aspx [ ^ ]。



可能需要两个值: System.Windows.Forms.Appearance.Button System.Windows.Forms.Appearance.Normal

http://msdn.microsoft .com / zh-CN / library / system.windows.forms.appearance%28v = vs.110%29.aspx [ ^ ]。



那就是我t。



-SA
Sorry if my answer does not meet your expectations, but it could be because your formulation of the problem is complete mess — please see the comments to the question.

If I understand your idea, you would like to have a control to carry a Boolean value. Is so, this is a CheckBox:
http://msdn.microsoft.com/en-us/library/system.windows.forms.checkbox%28v=vs.110%29.aspx[^].

And yes, you can visually represent it as a button. True is represented by depressed button latched in this state, and False when the button is up. Here is how: you can control CheckBox.Appearance with this property:
http://msdn.microsoft.com/en-us/library/system.windows.forms.checkbox.appearance%28v=vs.110%29.aspx[^].

It can take two values: System.Windows.Forms.Appearance.Button and System.Windows.Forms.Appearance.Normal:
http://msdn.microsoft.com/en-us/library/system.windows.forms.appearance%28v=vs.110%29.aspx[^].

That's it.

—SA


这篇关于如何将布尔值绑定到c#中的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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