如何将布尔值绑定到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 aCheckBox
:
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 controlCheckBox.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
andSystem.Windows.Forms.Appearance.Normal
:
http://msdn.microsoft.com/en-us/library/system.windows.forms.appearance%28v=vs.110%29.aspx[^].
That's it.—SA