防止用户取消选中复选框
我的 winforms 程序中有 3 个复选框。我设法以某种方式使用户只能选择其中之一。也就是说,如果用户单击其中一个未选中的按钮,当然该按钮将被选中,并且该选中将从最后选中的按钮中删除!
现在我想以某种方式做到这一点,用户无法取消选中复选框,因此选中复选框的唯一方法是单击它。这可能吗?有这方面的财产吗?
很抱歉使用了太多的支票&盒子:P
I have 3 checkboxes in my winforms program. I managed to make it somehow that only one of them can be selected by user. That is if user clicks one of the unchecked buttons, ofcourse that button will be checked and also the check will be removed from last checked button!
Now I want to do it somehow that user can not uncheck the checkboxes, so the only way to checkk a box will be clicking on it. is this possible? is there any property for this?
Sorry for using too much check & box :P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 checkedchanged 事件中在复选框中写入以下代码。
In the checkedchanged event of the checkbox write the following code.
如果您想要单选按钮功能但需要不同的外观,请更改单选按钮的外观。
来自 http://msdn .microsoft.com/en-us/library/system.windows.forms.radiobutton(v=vs.80).asp
If you want a radio button functionality but a different look, change the appearance of a radio button.
From http://msdn.microsoft.com/en-us/library/system.windows.forms.radiobutton(v=vs.80).asp
只需监听更改事件,如果该事件告诉您该复选框已被取消选中,请重新选中它。
但我同意其他人的观点,这种行为是 RadioButtons 的行为之一,因此请使用单选按钮。您不想迎合您的个人感觉,而是想为最终用户提供统一的用户体验。这是 Microsoft(以及所有其他框架)准则的一部分。
Just listen for change events and if the event tells you the checkbox has been unchecked, recheck it.
But I agree with others, this behavior is the one of RadioButtons, so use a radio button instead. You don't want to suit your personal feeling but to provide a unified user experience to the end user. That's part of the guidelines of Microsoft (and every other framework).