How to: Split two areas with a bar
Let the user widen a list at the expense of the subform next to it (or enlarge a chart above a table at the expense of the table) by dragging a bar between them.
Requires WKL Forms Object Library 1.23 or later.
Solution overview
Place a WklSplitter in the gap between the two areas. With no settings, it moves the controls
that lie alongside it within 20 pixels; FirstControls and SecondControls name the controls
explicitly instead. Orientation sets the direction, MinSizeFirst and MinSizeSecond set the
limits, and CollapseSide sets the side that a double-click collapses. Position is the bar's
offset from its designed position, in twips.
Implementation
In Design view, choose Form Design › Controls › ActiveX Controls › WKL Splitter,
draw a narrow bar in the gap (for example, 0.05 in. wide and as tall as the areas), and name it
Split1. The designer ([...] in the Custom row, Splitter page) shows which controls it
found on each side. To make the settings in code, for example in Form_Load:
With Me!Split1.Object
.FirstControls = "lstCustomers" ' empty: found by position
.SecondControls = "sfOrders;lblOrders" ' several controls per side
.MinSizeFirst = 1500 ' twips each control keeps on its side
.MinSizeSecond = 3000
.CollapseSide = wscFirst ' a double click folds the list away
End With
To react to the user, or to move the bar from code:
Private Sub Split1_BeforeSplit(Position As Long, Cancel As Integer)
If Position > 4000 Then Position = 4000 ' change the new offset, or Cancel = True
End Sub
Private Sub cmdWideList_Click()
Me!Split1.Object.Position = 2000 ' code raises no BeforeSplit/AfterSplit
End Sub
Remarks
- Controls on the first side (left or top) change their width or height; controls on the second side move their near edge and keep their far edge. Controls beyond the areas stay where they are.
- On an Access form, only controls in the splitter's own section count. Areas found by position must lie alongside the bar: a heading text box above both areas isn't a neighbor.
- Keep the areas anchored at the top left. Access stretches anchored controls without notifying the object model, and the splitter calculates every arrangement from the designed positions.
Position,Collapsed, andLayouttake effect only in Form view. The arrangement is remembered for each Windows user unlessAutoSaveLayoutis False; see How to: Keep the user's arrangement.- For more than two areas that should use the whole window, use a single
WklDockLayoutinstead of several splitters.