选中验证复选框 [英] Validate checkbox is checked

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

问题描述

我有3个要验证的复选框,当我单击打印按钮时,至少检查了一个复选框。当我点击打印时,它提示我选择至少一个复选框,当我对它打印的消息说好的时候。我怎么能停止它?





I have 3 check boxes that i want to validate at least one is checked when i click the print button. when I click print it prompts me to select at least one check box when I say ok to the message it prints anyway.How can i stop that?


<pre>private void btnPrint_Click(object sender, EventArgs e)
        {

            try
            {

                if (checkBox1.Checked)
                    if (checkBox2.Checked)
                if (checkBox3.Checked)
                    {

                    }
                if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    MessageBox.Show("Please select at least one!");
                }
            }


            catch (Exception ex)
            {

                printDocument1.PrintPage += printDocument1_PrintPage;
                printDocument1.Print();
            }
        }





我的尝试:



相关条目和互联网搜索



What I have tried:

Related entries and internet search

推荐答案

为什么在选中其中一个复选框之前不禁用Button?

Why don't you disable the Button until one of the checkboxes are checked?
private void CheckChanged(object sender, EventArgs e)
{
    button1.Enabled = checkBox1.Checked || checkBox2.Checked || checkBox3.Checked;
}


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

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