How to: Choose the areas of a layout
Specify which controls a WklDockLayout arranges, in which zone, and with what minimum size,
instead of letting it find them by position; for example, when two areas could be interpreted
either way, or when code shows and hides areas.
Requires WKL Forms Object Library 1.23 or later.
Solution overview
Panes lists the areas in docking order as Name=Zone or Name=Zone,MinSize (in twips),
separated by semicolons; the zones are Left, Top, Right, Bottom, and Fill.
Name=Zone:Group turns areas into cards of one tab group
(How to: Build a side bar with cards); with a minimum size, the
group comes first: Name=Zone:Group,MinSize (sfEditMain=Right:Side,3402; Right,3402:Side is
rejected). A group counts as one area, and its minimum size is the largest of its cards. When
Panes is empty, the layout finds the areas by position. Either way, PaneNames returns the areas
the layout uses. MinPaneSize is the minimum for entries that don't specify one. Refresh reads
the positions again after code has moved controls permanently.
Implementation
In the designer ([...] in the Custom row), on the Areas page, Take over by position
fills the list with the areas found by position; you can change the zones and minimum sizes there.
To do the same in code:
' Navigation outermost on the left, a log strip at the bottom under the main area only. Me!Layout1.Object.Panes = "sfNavigation=Left,1500; sfMain=Fill; sfLog=Bottom,800" Debug.Print Me!Layout1.Object.PaneNames ' sfNavigation;sfMain;sfLog
Docking order matters: an earlier entry is docked farther out and spans the full height or width
that's left when its turn comes. If sfLog=Bottom were listed before sfNavigation=Left, the log
strip would span the whole width, below the navigation as well.
To change an area at run time:
With Me!Layout1.Object
.PaneZone("sfLog") = wdzRight ' move the log to the right edge
.PaneSize("sfNavigation") = 3000 ' width of a left or right area, height of a top or bottom one
.PaneCollapsed("sfLog") = True ' take it away: the others get its room, its strip stays at the edge
End With
Collapse an area with PaneCollapsed rather than setting its Visible property. The layout
arranges areas by their zones, sizes, and collapsed state, so a control hidden through Visible
keeps its space.
Remarks
- When it finds areas by position, the layout takes the controls inside its rectangle off its edges in turn: a control along one entire edge is docked there, the thinnest first, and the largest remaining control fills the rest. Only visible controls in the layout's own section count.
- Every docked area keeps its designed width or height. When the window gets too small, the fill area shrinks first, then the docked areas from the inside out, each down to its minimum size.
- An invalid
Panesstring raiseswkeInvalidValueimmediately; a name that doesn't exist on the form raises it when the layout first arranges the areas. - Setting
Panesin Form view reads the areas again, just asRefreshdoes, and discards the user's arrangement. - Leave the areas' anchors to the designer: with Set up on applying, it gives each area the horizontal anchor that matches its position and keeps the vertical anchor at the top. Don't set the anchors by hand.