Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toggle Group Box Visibility

Tags:

c#

winforms

I have two Group Boxes grpMeter and grpTag. I have to place grpMeter over grpTag.. both need same location and size..

On button click, I have to make them visible alternately. Is it possible? I tried many times but only 1 group box becomes visible. Maybe because of the overlapping problem. I tried with panel, but the same problem arises. Is there any solution?

public void ShowMeter()
{
    grpMeter.Visible = true;
    grpTags.Visible = false;
}

public void ShowTag()
{
    grpTags.Visible = true;
    grpMeter.Visible = false;            
}
like image 937
Krish KvR Avatar asked Dec 05 '22 10:12

Krish KvR


2 Answers

Place both group boxes next to each other so that they don't overlap and see if it works then. If you made it work, don't move the one group box with the mouse, but select it only and then set the coordinates manually in the Properties list.

That way you can prevent the one group box from accidentially becoming the child of the other group box.

like image 59
Thorsten Dittmar Avatar answered Dec 17 '22 10:12

Thorsten Dittmar


Try this logic inside a button_click event:

private void btn_Click(object sender, EventArgs e)
{
    if (grpTags.Visible)
        ShowMeter();
    else
        ShowTag();
}
like image 25
Spaceman Avatar answered Dec 17 '22 12:12

Spaceman