且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将布尔值绑定到c#中的按钮?

更新时间:2022-01-15 17:42:35

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



如果我理解你的想法,你想要一个控件来携带一个布尔值。是这样,这是一个 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