question

IvanGallardo-2186 avatar image
0 Votes"
IvanGallardo-2186 asked IvanGallardo-2186 answered

Whats wrong with the states of the check boxes?

c# with windows forms.

It seems that there's some event that's sticking in the behavior, and I don't understand which and how to disable it.

I have checkboxes that should show three labels and a panel in common with other checkboxes and show its own. Once you uncheck, it should verify if there's another checkbox checked and if it's true, should keep the labels and the panel visible and hide it own label, but the last unselected should hide the panel and the three labels with it own.

The code I have.

 public void chBox()
         {
               
             foreach (CheckBox boxes in panel3.Controls)
             {
                 if (boxes.Checked == true)
    
                     panel4.Visible = true;
                 else
                     panel4.Visible = false;
             }
    
         }
 private void checkBox1_CheckedChanged(object sender, EventArgs e)
         {
               
             if (checkBox1.Checked)
             {
                 chBox();
                 label4.Visible = true;
             }
             else
             {
                 label4.Visible = false;
             }
                
         }
    
         private void checkBox2_CheckedChanged(object sender, EventArgs e)
         {
                
             if (checkBox2.Checked)
             {
                 chBox();
                 label6.Visible = true;
             }
             else
             {
                 label6.Visible = false;
             }
         }


Thanks a lot if somebody can give a Hint.


dotnet-csharpwindows-forms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

Check if this works:

 public void chBox()
 {
    panel4.Visible = false;
    foreach (CheckBox box in panel3.Controls)
    {
       if (box.Checked) 
       {
          panel4.Visible = true;
          break;
       }
    }
 }

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IvanGallardo-2186 avatar image
0 Votes"
IvanGallardo-2186 answered

Sorry but I just solved with a counter, I did try with a break but I couldn't make it.

The counter is between 0 and 1, and then I called the method in every click which adds their own label.

Thanks a lot.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.