Check if this works:
public void chBox()
{
panel4.Visible = false;
foreach (CheckBox box in panel3.Controls)
{
if (box.Checked)
{
panel4.Visible = true;
break;
}
}
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
Check if this works:
public void chBox()
{
panel4.Visible = false;
foreach (CheckBox box in panel3.Controls)
{
if (box.Checked)
{
panel4.Visible = true;
break;
}
}
}
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.