C#同时选择多个复选框 [英] C# Selecting Multiple Check Boxes at the same time

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

问题描述

大家好,



我在一个组合框中有五个复选框,每个框在另一个单选按钮组上有不同的选项。



如果我一次选中一个复选框,我可以在单选按钮中实现我应该达到的目的。

但如果我选择多个支票任何顺序的框,我只是实现了我点击的最后一个复选框。但我也需要实现其他复选框的目的。

如何实现这一目标?任何简单的逻辑???



请用最少的编码帮助我解决这个问题。

提前致谢。



以下是以下行代码,



Hi all,

I have five check boxes in a Group Box, with each each box having different selections on another radio button Group.

If I select One check box at a time, I can achieve what I am supposed to in the radio button.
But if I select more than one check box in any sequence, I am just achieving the last check box that I clicked. But I need to achieve the other check boxes purpose too.
How can I achieve this??? Any easy logic???

Kindly help me in this to solve this with minimal coding.
Thanks in advance.

The following is the below line code,

private void chk_Balanced_CheckedChanged(object sender, EventArgs e)
{
    if (chk_Balanced.Checked == true)
    {
        radio_2ch.Enabled = true;
        radio_6ch.Enabled = true;
        radio_8ch.Enabled = true;
        radio_48.Enabled = false;
        radio_96.Enabled = false;
        radio_192.Enabled = false;
    }
}

private void chk_Unbalanced_CheckedChanged(object sender, EventArgs e)
{
    if (chk_Unbalanced.Checked == true)
    {
        radio_2ch.Enabled = true;
        radio_6ch.Enabled = true;
        radio_8ch.Enabled = true;
        radio_48.Enabled = false;
        radio_96.Enabled = false;
        radio_192.Enabled = false;
    }
}

private void chk_Headphone_CheckedChanged(object sender, EventArgs e)
{
    if (chk_Headphone.Checked == true)
    {
        radio_2ch.Enabled = true;
        radio_6ch.Enabled = false;
        radio_8ch.Enabled = false;
        radio_48.Enabled = false;
        radio_96.Enabled = false;
        radio_192.Enabled = false;
    }
}

private void chk_HDMI_CheckedChanged(object sender, EventArgs e)
{
    if (chk_HDMI.Checked == true)
    {
        radio_2ch.Enabled = false;
        radio_6ch.Enabled = false;
        radio_8ch.Enabled = false;
        radio_48.Enabled = true;
        radio_96.Enabled = true;
        radio_192.Enabled = true;
    }
}

private void chk_SPDIF_CheckedChanged(object sender, EventArgs e)
{
    if (chk_SPDIF.Checked == true)
    {
        radio_2ch.Enabled = false;
        radio_6ch.Enabled = false;
        radio_8ch.Enabled = false;
        radio_48.Enabled = true;
        radio_96.Enabled = true;
        radio_192.Enabled = true;
    }
}

推荐答案

步骤1:在Designer中选择所有五个复选框然后更改Checked_Changed事件为chkGroup_CheckedChanged





步骤2:然后用以下代码替换您的代码



Step 1: Select all Five Checkboxes in Designer then chang the Checked_Changed Event to "chkGroup_CheckedChanged"


Step 2: Then replace your code with following Code

private void chkGroup_CheckedChanged(object sender, EventArgs e)
       {
         if (sender.Equals(chk_Balanced))
           {
               radio_2ch.Enabled = true;
               radio_6ch.Enabled = true;
               radio_8ch.Enabled = true;
               radio_48.Enabled = false;
               radio_96.Enabled = false;
               radio_192.Enabled = false;
           }
           else if (sender.Equals(chk_Unbalanced))

           {
               radio_2ch.Enabled = true;
               radio_6ch.Enabled = true;
               radio_8ch.Enabled = true;
               radio_48.Enabled = false;
               radio_96.Enabled = false;
               radio_192.Enabled = false;
           }

           else if (sender.Equals(chk_Headphone))

           {
               radio_2ch.Enabled = true;
               radio_6ch.Enabled = false;
               radio_8ch.Enabled = false;
               radio_48.Enabled = false;
               radio_96.Enabled = false;
               radio_192.Enabled = false;
           }
           else if (sender.Equals(chk_HDMI))

           {
               radio_2ch.Enabled = false;
               radio_6ch.Enabled = false;
               radio_8ch.Enabled = false;
               radio_48.Enabled = true;
               radio_96.Enabled = true;
               radio_192.Enabled = true;
           }

           else  if (sender.Equals(chk_SPDIF))

           {
               radio_2ch.Enabled = false;
               radio_6ch.Enabled = false;
               radio_8ch.Enabled = false;
               radio_48.Enabled = true;
               radio_96.Enabled = true;
               radio_192.Enabled = true;
           }




       }


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

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