How to Move image with the mouse in a form
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 'Controls - How to Move image with the mouse in a form Option Explicit Private oX As Integer Private oY As Integer Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then oX = ScaleX(X, ScaleMode, vbPixels) oY = ScaleY(Y, ScaleMode, vbPixels) End If End Sub Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Static lX As Single Static lY As Single If lX = X And lY = Y Then Exit Sub lX = X lY = Y If Button = vbLeftButton Then X = X - ScaleX(oX, vbPixels, ScaleMode) Y = Y - ScaleY(oY, vbPixels, ScaleMode) Picture1.Move X + Picture1.Left, Y + Picture1.Top End If End Sub |