If statements for Checkboxes

前端 未结 6 1109
刺人心
刺人心 2021-02-18 23:43

I wanted to know how to write if statements to see if one or another check box is checked or not.

I have two check boxes. I wanted it to check to see if checkbox 1 is c

相关标签:
6条回答
  • 2021-02-19 00:08

    In VB.Net

    If Check1.checked and Not (Check2.checked) Then
    
    ElseIf Check2.Checked and not Check1.Checked then
    
    End If
    
    0 讨论(0)
  • 2021-02-19 00:12

    Your going to use the checkbox1.checked property in your if statement, this returns true or false depending on weather it is checked or not.

    0 讨论(0)
  • 2021-02-19 00:12

    I simplification for Science_Fiction's answer I think is to use the exclusive or function so you can just have:

    if(checkbox1.checked ^ checkbox2.checked)
    {
    //do stuff
    }
    

    That is assuming you want to do the same thing for both situations.

    0 讨论(0)
  • 2021-02-19 00:13
    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBoxImage.Checked)
        {
            groupBoxImage.Show();
        }
        else if (!checkBoxImage.Checked)
        {
            groupBoxImage.Hide(); 
        }
    }
    
    0 讨论(0)
  • 2021-02-19 00:14

    I'm making an assumption that you mean not checked. I don't have a C# compiler handy but:

    if (checkbox1.Checked && !checkbox2.Checked)
    {
    
    }
    else if (!checkbox1.Checked && checkbox2.Checked)
    {
    
    }
    
    0 讨论(0)
  • 2021-02-19 00:27

    I suggest

    if (checkbox.IsChecked == true)
    {
        //do something
    }
    

    Hope it's helpful ^^

    0 讨论(0)
提交回复
热议问题