0

So I am working on a program that has several screens which causes it to have overlapping controls (Buttons and lists).

I put the controls in panels which works great and then do show/hide for the panels.

This also works well.

I am having a problem now that I am up to several panels where when I move one panel up it gets absorbed by another and I need them to stay separate.

Example: When I move panel2 into place over panel1, panel2 becomes part of panel1. Then when I do panel1.Hide() and panel2.Show(), panel2 is still hidden because it is part of panel1. is there a way for me to ungroup these or move panel2 into place without it automatically becoming part of panel1? (I know I can show hide the controls inside of the panels, but this will add a lot of complexity because I have a ton of controls)

Perhaps there is a better solution than using panels?

Servy
  • 202,030
  • 26
  • 332
  • 449
Dr. Hoads
  • 79
  • 1
  • 8
  • 1
    The solution is to lay out your controls in code, rather than using the designer, so that your controls are laid out the way you want, rather than accidentally being nested inside of each other when they shouldn't be. – Servy Sep 27 '13 at 15:41
  • Thanks, I am not too familiar with this, but I checked out Form1.Designer.cs and was able to figure it out by modifying what was already there. Thanks!! – Dr. Hoads Sep 27 '13 at 15:52

1 Answers1

3

You can use the View + Other Windows + Document Outline tool window to get these panels separated again. Drag the inner panel back to the parent. You'll then also have to edit the Location property to get it back in the right position.

This is annoying of course and good odds that you'll have to do this repeatedly. There's a better way to go about it, a TabControl has good design-time support and also has the same "overlapping panel" metaphor. You just need to hide the tabs at runtime. That's pretty easy to do, check the StackPanel control in this answer.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 1
    Assuming the panels don't just *overlap* but *exactly coincide* then yes a `TabControl` is the best method. – Ben Voigt Sep 27 '13 at 15:58
  • Ok, Wow!! TabControl is totally the way to go for me(Control space does coincide)... Will make my life a lot easier. Just one problem. Depending on what you select, the overall background changes. I can set the color of each tab to transparent, but the overall tab control has no color settings. So I just have a gray background instead of seeing through to my intended background. Any thoughts? – Dr. Hoads Sep 27 '13 at 17:38
  • Not supported. The usual advice with transparency effects is to take a closer look at WPF. – Hans Passant Sep 27 '13 at 17:44
  • I reworked my program so that the entire program was within the tab control and then just changed the background images there. This has made the entire program much more manageable. Thanks so much for the tip!! – Dr. Hoads Sep 27 '13 at 21:37