Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common Practice - SplitContainer

Is it common practice to have a SplitContainer control, and then add another SplitContainer to it, and then add another, and another...?

It just seems like there should be a better way, I mean, once you get up to about 3 or 4 SplitContainers, you literally run out of space to work in, in Designer view.

like image 210
βӔḺṪẶⱫŌŔ Avatar asked May 16 '11 01:05

βӔḺṪẶⱫŌŔ


People also ask

What is the use of SplitContainer?

The SplitContainer control lets you create complex user interfaces; often, a selection in one panel determines what objects are shown in the other panel. This arrangement is very effective for displaying and browsing information.

What is splitter in C#?

Windows Forms Splitter controls are used to resize docked controls at run time. The Splitter control is often used on forms with controls that have varying lengths of data to present, like Windows Explorer, whose data panes contain information of varying widths at different times.


1 Answers

If you find yourself nesting too many SplitContainers, it's time to drop down a level and look at the Splitter control itself. Assume for a minute that we're talking about a bunch of horizontal rows like this:

+-----------+
| Content 1 |
+-----------+
| Content 2 |
+-----------+
| Content 3 |
+-----------+

Take the contents of your Content 1 section, and put them in some kind of container, such as a panel. Dock that panel to the top of the form. Now drag a Splitter control onto the form. It will probably start out oriented vertically, so change its docking to be "Top", and it will stick itself to the bottom of the Content 1 container. Now add another container to hold the "Content 2" stuff, dock it to the top. Add another Splitter, and dock it to the top. Finally, add the "Content 3" stuff in a panel, and set its docking behavior to "Fill". You can stack as many Splitters up as you want, this way.

By docking the splitters to the top, or to the bottom, they will figure out at runtime who their neighbors are, and how to resize them. This behavior is controlled entirely by the controls' "Z-Order", which should translate roughly as "the order the controls were added to the form" for most people. You can see and manipulate this in the "Document Outline" view, (View -> Other Windows -> Document Outine, or Ctrl-W, U). Experiment a little with an empty form, and it will all make sense.

like image 139
Mel Avatar answered Sep 29 '22 00:09

Mel