Microsoft Office Tutorials and References
In Depth Information
A UserForm with Movable Controls
A UserForm with Movable Controls
Iā€™m not sure of the practical significance of this technique, but the example in this section will
help you understand mouse-related events. The UserForm shown in Figure 15-13 contains three
Image controls. The user can use the mouse to drag these images around in the dialog box.
Figure 15-13: You can drag and rearrange the three Image controls by using the mouse.
This example is available on the companion CD-ROM. The file is named
move controls.xlsm .
Each of the Image controls has two associated event procedures: MouseDown and MouseMove .
The event procedures for the Image1 control are shown here. (The others are identical except
for the control names.)
Private Sub Image1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ā€˜ Starting position when button is pressed
OldX = X
OldY = Y
Image1.ZOrder 0
End Sub
Private Sub Image1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ā€˜ Move the image
If Button = 1 Then
Image1.Left = Image1.Left + (X - OldX)
Image1.Top = Image1.Top + (Y - OldY)
End If
End Sub
 
Search JabSto ::




Custom Search