Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Dock

This method lets you dock or undock a toolbar programmatically. You pass the appropriate position.

Usage

tbrToolBar.Dock( nDockPosition [, nXPosition, nYPosition ] )

Parameter

Value

Meaning

nDockPosition

-1

Undock the toolbar.

0

Dock the toolbar at the top.

1

Dock the toolbar at the left.

2

Dock the toolbar at the right.

3

Dock the toolbar at the bottom.

nXPosition, nYPosition

Omitted

Put the toolbar at the next available position on the specified side. For undocking, return the toolbar to its last undocked location.

Numeric

Position the toolbar at the specified location. For each dock position, only one of the two coordinates is used (nXPosition for top and bottom, nYPosition for the sides). For undocking, put the toolbar at the specified location.

When you don’t specify a position, VFP’s interpretation of the “next available position” may not be the same as yours. In particular, the chosen position depends on where the toolbar has been docked before and where it’s coming from.

Dock fires several events, depending on the value of nDockPosition. The exact firing sequence is different in different versions of VFP. In VFP 6 and later versions, BeforeDock fires first, then AfterDock fires, except when nDockPosition is -1. In that case, Undock fires first, followed by BeforeDock. If the toolbar is visible, Dock updates both Docked and DockPosition. If the toolbar isn’t yet visible, those properties aren’t updated until the toolbar is SHOWn. In VFP 3, using Dock to move from one docked position to another fires BeforeDock, Undock, then BeforeDock and AfterDock. This is a different sequence than you see when you move from one docked position to another with the mouse. In that case, only BeforeDock and AfterDock fire. In VFP 5 and later versions, no matter how you dock the toolbar, only BeforeDock and AfterDock fire.

It is, of course, frustrating to have firing sequences change along the way and, to be honest, we’re not convinced that they’ve got it right quite yet. BeforeDock, followed by AfterDock, feels right for docking, regardless of whether you’re initially docking the thing or moving it from one position to another (though we could argue for a call to Undock first in the latter case). But, why does BeforeDock fire when you undock a toolbar?

Example

* Dock a toolbar at the bottom
ThisFormSet.tbrNavButtons.Dock(3)

* Undock a toolbar and put in at a specific position
ThisFormSet.tbrStandard.Dock(-1,100,100)

See Also

AfterDock, BeforeDock, Docked, DockPosition, Toolbar, Undock