Wednesday, June 14, 2006

Taming Dockable Toolbars

Last night I spoke at LAFOX on docking in VFP. Before my session started Ken Leland approached me about a problem he has in his application that's come up with several customers of mine over the years and we've never really tracked down.

The problem is that occassionally a toolbar will become undocked and the end user claims they didn't move it or anything like that. In fact, this problem can occur even if the movable property of the toolbar is set to false. From looking at the various office applications, it appears standard Windows behavior is for a toolbar to doc itself when you doubleclick on an empty space in it, or in its titlebar. VFP decided to go one better than than and if you doubleclick on a toolbar or empty space in it (including on a separator), the toolbar will undock itself - even if movable is set to false. The result is that if a user misses a button in a docked toolbar by a pixel or two and clicks in an empty space, the toolbar will undock. Turning off this behavior is easy all you need is a little code like this in the dblclick method.


IF This.DockPosition <> -1
NODEFAULT
ENDIF


That'll tame your toolbar.