views:

2596

answers:

4

If you create a panel on a form and set it to Dock=Top and drop another panel and set its Dock=Fill, it may fill the entire form, ignoring the first panel. Changing the tab order does nothing.

+18  A: 

Right click on the panel with Dock=Fill and click 'Bring to Front'.

This makes this control be created last, which takes into account the Dock settings on other controls in the same container.

Jeff Cuscutis
Simple, Godsend, this had really been annoying me
smirkingman
+2  A: 

Another, potentially cleaner option is to use the TableLayout control. Set up one row of the desired height for your top dock, and another row to fill 100% for your bottom. Set both panels inside to Fill, and you're done.

(TableLayout does take some getting used to, though.)

John Rudy
TableLayout is also slower than docking conterols for layout performance, particularly if you have nested usercontrols which use TableLayout. However, it does yield a nice layout to be sure.
Nick
Is this performance hit something an average user would see in a simple case of two panels, as described above? Or is it something they notice when you have dozens of UCs, all with layouts, all in one layout? (Ironically, the app I'm currently working on is like that, and performance seems OK ... )
John Rudy
A: 

Here is a trick that worked for me..

Place the Top item and dock it top.

Place a Splitter, and also dock it top, then set it disabled (unless you want to resize the top).

Then Place the Fill object and set Docking to Fill. The object will stay below the splitter.

John Christman
+7  A: 

Docking layout depends on the order of sibling controls. A docked controls only take the layout of previous docked siblings into account. Hence the control with Dock=Fill should be last in the sibling order, if you want it to take the other docked controls into account, and not just be overlapped by them.

This can be confusing because the sibling-order is not necessarily the same as the visual order, and the sibling order is not always apparent from the design view.

The Document outline window (View -> Other Windows -> Document outline) gives a useful tree-view over the control hierarchy and order, and allows you to change the sibling order of controls.

You can also change sibling order directly in the designer by context menu -> Bring to front / Send to back, which moves the control to be first or last of the siblings. These menu labels may be somewhat confusing since the actual effect depends on the layout model.

With fixed positioned controls, the 2D position is independent of the sibling order, but when controls are overlapping, the control earliest in the order will be "on top", hiding part of siblings later in the order. In this context Bring to front / Send to back makes sense.

Inside flow- or table-layout panels, the creation order determines the visual order of the controls. There is no overlapping controls. So bring to front/send to back really means make first or last in the order of controls.

With docked layout, the bring to front / send to back may be even more confusing since it determines in which order the docking is calculated, so "bring to front" on a fill-docked control will place the control in the middle of the parent, taking all edge-docked controls into account.

JacquesB
i have a panel, status strip, and menu strip all on a form and it seems that when i dock the menu strip to the top, the status strip to the bottom, and fill the panel, the panel doesnt fill the space in between the two strips unless it is the first sibling (at the top of the Document Outline window above the two strips). Moving the panel down (towards "last") covers over the strips.So should the Dock=Fill control actually be the first sibling in the order? Am i reading this wrong?i'm using 3.5 (2008). Did this change?
Jugglingnutcase