Search code examples
c#.netwinformsgroupbox

Visibility bug with group box


I have a form with 2 radio buttons and for each of them, one group box is related when they are checked (radio button 1 shows group box 1 and hide group box 2 / radio button 2 shows group box 2 and hides group box 1). It works perfectly fine but I need to force the display of one group box depending of which server the user connect and when I do that I'm hiding radio buttons to not leave any choice for the user. So I do someting like that :

 if(m_lastSelectedNode.Text == "server1")
                {
                    label1.Visible = false;
                    label2.Visible = true;
                    MainForm_GroupBox_1.Visible = false;
                    MainForm_GroupBox_2.Visible = true;
                }
 else if (m_lastSelectedNode.Text == "server2")
                {
                    label1.Visible = true;
                    label2.Visible = false;
                    MainForm_GroupBox_1.Visible = true;
                    MainForm_GroupBox_2.Visible = false;
       
                }
 else
                {
                    label1.Visible = false;
                    label2.Visible = false;
                    MainForm_GroupBox_1.Visible = true;
                }

So what happen here is when i'm connecting to server1 for showing only groupbox 2 it doesn't work and moreover if i come back to a classic server and trying to do the regular thing with radio button, groupbox2 won't be shown (no problem on group box 1) but if i'm first connecting to a regular server, doing the regular thing with radio button for showing group box 2 and then connecting to the server 1, it'll work the way i wanted.

I don't understand how is it possible, i don't have issue with label that hide radio button and for the two group box it's not an overlap issue so any suggestion here ?


Solution

  • I found a solution by giving up the visible parameter. I set both group box visible to true by default and I choose to change the location for hiding them instead of using visible. I guess it's not optimal but it works.