Windows应用程序中的CheckBox验证 [英] CheckBox validations in windows application

查看:88
本文介绍了Windows应用程序中的CheckBox验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我正在C#中运行Windows应用程序.我有10个复选框&当我选中第二个CheckBox&单击该按钮,我需要进行验证,是否选中了前一个或后一个复选框.如果选中了前一个或后一个复选框,则该对复选框应被禁用.任何人都可以帮忙.


问候
Aabi

Hi friends,

I am working windows application in C#.I have 10 checkboxes & a Button.When I check the 2nd CheckBox & click the button,I need to do a validation whether the succeeding or the preceding checkboxes are checked or not.If any one of the succeeding or the preceding checkboxes are checked then that pair of checkboxes should get disabled.Can anyone help.


Regards
Aabi

推荐答案

应根据其他控件的状态而不是其自身的状态来启用或禁用控件.您说如果选中了任何一个后续或前面的复选框,则该对复选框应被禁用",这是错误的.因为如果选中了这些复选框并被禁用,则无法让用户取消选中它们.

因此,可以说您想在选中checkbox1时禁用checkbox2.

Controls should be enabled or disabled based on the state of other controls, not its own state. You stated "If any one of the succeeding or the preceding checkboxes are checked then that pair of checkboxes should get disabled" which is wrong. Because if those checkboxes are checked and they''re disabled, then there is no way of allowing the user to uncheck them.

So you can say that you want to disable checkbox2 when checkbox1 is checked.

private void checkBox1_CheckedChanged(object sender, EventArgs e) {
    checkBox2.Enabled = !checkBox1.Checked;
}



您可以编写类似的代码来获得要执行的操作.



You can write similar code to get to what you are trying to do.


这篇关于Windows应用程序中的CheckBox验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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