LostPhysx
LostPhysx

Reputation: 3641

How to make Panel Visible in WinForms?

I have the following Code:

marathonPanel.Visible = false;
resultPanel.Visible = true;

but only the marathonPanel gets invisible and the resultPanel stays invisible. When I check the value of resultPanel.Visible it is set to false.

I also tried

resultPanel.BringToFront();<br>
resultPanel.Visible = true;

Can anyone help me?

Upvotes: 0

Views: 10540

Answers (3)

user2648274
user2648274

Reputation:

There is another way to find out such issues . if you look at *.resx file , it will tell which control is taking place as parent and which is child

Also you can view this thing in Document outline which is available in Visual Studio.

Upvotes: 0

Steve
Steve

Reputation: 216243

This happens when you design two overlapping panels in Visual Studio Form Designer. It is too easy to drag one panel inside the other and the dragged one becomes the child of the first.

I usually draw the panels in different locations. The first one in the expected place, the second one in a different place, then at Runtime move the second one on the same spot of the first one.

in Form_Load

 resultPanel.Left = marathonPanel.Left;
 resultPanel.Top = marathonPanel.Top;

Upvotes: 4

Hans Passant
Hans Passant

Reputation: 941217

This is a common designer accident, caused by Panel being a container control. Overlapping two panels is a problem. Your resultPanel will end up as a child of marathonPanel. So when you make marathonPanel invisible, the child will always be invisible as well.

Use View + (Other Windows) + Document Outline to fix the problem. Drag resultPanel and drop it on the form. Edit the Location property by hand, don't move the control with the mouse or the panel will suck it right back in.

Another way to do it is to intentionally mis-place it so it won't be sucked-up and fix the Location property in the form constructor. A more friendly hack that works better in the designer is to use a TabControl instead. Check the sample StackPanel in this answer.

Upvotes: 2

Related Questions