Ungroup panels? - c#

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?

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.

Related

Split container with three panels

I have an interesting little problem. I'm using a one parent split container on the main form and multiple panels. I dropped three panels in the container. Two of them on the top (panel 1) and one on the bottom (panel 2). The problem I'm having is the two on the top in panel 1. Trying to work with the two panels on the top I'm using the properties to select them. Although the properties appears to select the panel, it does not bring it to the front in the designer so that I can work on it
Does anyone have an idea how to work with panels so that they can be selected and design?
Do I need to use a split container for each panel? I sure hope not. :-(
Thank you in advance.
It seems that the document viewer is the place to go. Under View, Other Windows, Document Outline (Ctrl+Alt+T). The Treeview may be expanded so just locate the split container and collapse the panels. Simply drag-and-drop the panel that you need to view directly under the split container panel (in my case splitContainer.panel1). Now the panel should be in focus and viewed. Oh, one more thing. Make sure the panels are docked.
That should do it... :)

Why do some objects appear on top of others, and not always like that?

I created 2 empty labels, using winforms, to cover some groupboxes
They were created exactly the same way, but they dont behave the same way
The first one:
The second one:
The first covers everything, the second one only covers one groupbox, and displays the other two.
I tried the right click+ send to back /send to front, but I believe this doesn't mean anything in the code, it only purpose is to allow you to visualize better what you are placing in your form, I guess.
Can someone shed some light?
Groubox, Panel, TabPage etc are containers in which we keep controls. Form itself is also a container..
When you drag a label or any other control to place in a form, and if you want to hide the other controls, you should place the label in the form itself and the label should not become child of any of the groupBoxes.
For that the left top corner of the label you drag should not go inside any of the groupBoxes. This is only when you drag. If you want to position at a point inside groupBox, then Drag the control outside the groupBox and then use keyboard arrows to position, this will not let the control to become child of the groupBox. You can also set position on property window.

Delete a SplitContainer without deleting other controls

I can't believe I couldn't find the answer to this....
I no longer need to use a SplitContainer in my WinForms UI. But whenever I delete the SplitContainer, I lose all of my other controls too -- buttons, labels, textboxes, and charts. Anything that was in the SplitContainer is deleted as well. Very annoying.
What is the best way to remove a SplitContainer control but leave everything else in place?
Trivial Example:
Make room on your form and drag those controls into the empty space.
Alternatively, go to View - Other Windows - Document Outline and move the child controls out of the SplitContainer's hierarchy.
Do not cut and paste since that will sever your event handlers.

Prevent Child Components when Overlapping Panel

I have a WinForms application which has two panels which individually contain a usercontrol component (one in each panel). How ever, because both panels are the same size and in the same location, the top most panel becomes a child of the other panel. I want to be able to hide one panel and then show the other panel:
this.panel1.visibile = false;
this.panel2.visibile = true;
But when I hide panel1, the second panel is hidden as well.
How can I make panel2 a non-child of panel1?
I like to keep things simple because I'm new to C# Programming.
This is a common accident in the designer. Dropping the second panel on top of the first one will make it a child of the first panel. Two basic strategies to fix this:
View + Other Windows + Document Outline. Click the second panel in the list and drag it to the form. You'll need to fix up the Location property by hand by typing its value in the Property window.
Keep the upper left corner of the second panel just a bit to the left or top of the first panel. Put it in the right place in the form's constructor by assigning its Location property after the InitializeComponent() call.
Check this answer for a control that works well at design time and lets you easily flip panels at runtime.
The designer will do this automatically because it assumes that when you drag one control over another, you want to make it a child of that control.
What I usually do to get around this is to create the control in a different place on the form, and then use the properties to manually match the positions of sizes of the two controls.

C#: Anchored Panel won't resize properly

I've a strange problem regarding auto sizing of a panel in a user control. This panel is anchored to all 4 sides of the user control.
But the anchoring not always works as it should:
If the user control is resized by resizing the form, the right and bottom anchors don't work. But if the control is resized by using a splitter which is in the form, it works correctly.
All other controls which are also affected by resizing work correctly, just this panel won't do.
I can't see the difference between resizing through a splitter and through a form.
Setting the size manually in the OnResize of the UserControl only works if the resizing is done by moving the splitter. If the resizing occurs by resizing the form, the heigth and the width of the panel won't change to the new values.
Edit: To make it more clear: The user control is added to a TabPage and set to Dock=DockType.Fill.
Edit2: To make it more complicated: This is the hierarchy the control is used:
The Form contains a splitter with 2 controls (A and B). (B) contains a user control (C) with a splitContainer. The split container->panel1 in (C) contains a tabcontrol (D). This tabcontrol (D) contains a user control (E) (in a tabpage) . This user control (E) has a splitcontainer (F) in which another usercontrol with a tabControl (G) is placed. This tabcontrol (G) has tabpages, and in this pages is the described user control (H) placed.
If I place the control (H) directly to the panel in the splitcontainer (C) everything works fine. Since all controls which are added to a splitcontainer or a tabpage are set to docktype=fill, I cannot see why the last control has this problems.
Is there any limitation in the Windows Forms framework which limits the amount of child controls?
Edit: I have uploaded a TestApplication with which you can reproduce this issue.
http://rapidshare.de/files/49092516/TestApplication.zip.html
It occurs only under Vista. Win XP and 7 work properly...
If you resize the form, the textBox with the "..." button won't resize, but if you resize via the vertical splitContainer, it works.
There is a bug with deep nesting where the kernel runs out of stack space causing resizing, docking and anchoring to fail silently.
See https://web.archive.org/web/20140818095718/http://support.microsoft.com/kb/953934
You have talked about both "anchor" and "dock", which can serve similar purposes but act differently. Your problem may be that you are trying to do both, and this is interfering with the behavior you want. If not, perhaps try switching from the one to the other.
It sounds like you've double checked the ansectery of the control, but did you examine it with: View->Other Windows->Document Outline (a very handy tool I only recently discovered)?
Finally, while it doesn't directly solve your problem, it sounds like you have a very complicated UI, and your users may benefit if you were to spend some time to consider if you could simplify the UI. Of course, I don't know your users or the purpose of the app, and what you have may be the best, but it sounds like it might be time to ask this question.
Good luck.
The problem is not the depth of nesting; controls can be nested arbitrarily deep. Anchoring and Docking generally do not play nicely with each other. I usually favor docking over anchoring, but, whichever solution you choose, you should probably avoid mixing them.

Categories