|
|
Title | Make a dockable toolbar |
Keywords | dockable, ToolBar |
Categories | Tips and Tricks, Controls |
|
|
In the toolbar's MouseUp event handler, see which edge of the form is closest to the mouse. Dock the toolbar on that edge.
Unfortunately the program does not give visual feedback while the user drags the mouse.
|
|
' See which edge is closest to the mouse.
Private Sub Toolbar1_MouseUp(Button As Integer, Shift As _
Integer, x As Single, y As Single)
Dim dist_to_top As Single
Dim dist_to_left As Single
Dim dist_to_right As Single
Dim dist_to_bottom As Single
Dim smallest As Single
' See which is closest.
dist_to_top = Toolbar1.Top + y
dist_to_left = Toolbar1.Left + x
dist_to_right = Toolbar1.Left + ScaleWidth - x
dist_to_bottom = Toolbar1.Top + ScaleHeight - y
smallest = dist_to_top
If smallest > dist_to_left Then smallest = dist_to_left
If smallest > dist_to_right Then smallest = _
dist_to_right
If smallest > dist_to_bottom Then smallest = _
dist_to_bottom
' Move the toolbar.
If dist_to_left = smallest Then
Toolbar1.Align = vbAlignLeft
ElseIf dist_to_top = smallest Then
Toolbar1.Align = vbAlignTop
ElseIf dist_to_right = smallest Then
Toolbar1.Align = vbAlignRight
Else
Toolbar1.Align = vbAlignBottom
End If
End Sub
|
|
Formatted by
Neil Crosby
|
|
|
|
|
|