Color scheme: Riviera
You are here: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » WKL Forms Object Library how-to guides » How to: Use the layout controls on UserForms

How to: Use the layout controls on UserForms

Give an Excel or Word UserForm a navigation list, a main area, and a details strip that follow the form's size and that users can resize, without any code in UserForm_Resize.

Requires WKL Forms Object Library 1.23 or later.

Solution overview

WklDockLayout and WklSplitter work on UserForms (MSForms) just as they do on Access forms. The dock layout watches the UserForm window itself, because MSForms doesn't resize any controls along with the form; the splitter asks MSForms to activate it when the mouse pointer enters it, so the first press already starts a drag. Sizes are in twips in both hosts (1 point = 20 twips), and the arrangement is remembered in the current user's registry.

Implementation

In the Visual Basic Editor, choose Tools › Additional Controls, and select WKL Dock Layout (and WKL Splitter, if needed); both then appear in the Toolbox. Draw the areas (for example, ListBox1 along the left edge, ListBox3 along the bottom, and ListBox2 in the rest), then draw the dock layout over them, name it Layout1, and choose Format › Order › Send to Back.

Nothing else is needed. With FillSection (the default), the layout takes up the inside of the UserForm, finds the three list boxes by position, and follows every size of the form, including when code sets the form's Width and Height, as shown below. Code works with the control directly, without .Object:

Private Sub UserForm_Initialize()
    Me.Width = 600                              ' points
    Me.Height = 400
    Me.Layout1.LayoutKey = "Orders.Layout1"     ' the same form name in another document stays apart
End Sub
 
Private Sub cmdDefault_Click()
    Me.Layout1.Reset
End Sub

Remarks

  • With FillSection off, the layout keeps the distance from the UserForm's right and bottom edges that it had when the form was first shown.
  • MSForms places controls on whole pixels, so an edge can differ from the calculated point value by up to 0.75 point.
  • The arrangement is stored under HKEY_CURRENT_USER\Software\The White Knight Labs\Access Framework\Layouts, one value per LayoutKey; the default key is “UserForm name.control name”.
  • When the workbook opens, Excel might ask whether to enable the UserForm's ActiveX controls.
  • After an update of the WKL Forms Object Library, a member that's new in that version might not compile on a UserForm in a document that was used before; see "Method or data member not found" for a control on a UserForm.
  • F6 between the areas works only on Access forms. Keyboard support for the bar and splitter bars (Tab, arrow keys, and Enter) and their UI Automation support are available on Access forms but not on UserForms.
en/wiki/msaccess/comctl/how-to/use-layout-controls-on-userforms.txt · Last modified: by Wolfgang van der Stille