DragPicture




Public Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long

Public Type POINTAPI
X As Long
Y As Long
End Type

Global iTPPY As Long
Global iTPPX As Long

Dim bMoveFrom As Boolean, LastPoint As POINTAPI

Private Sub Form_Load()
iTPPX& = Screen.TwipsPerPixelX
iTPPY& = Screen.TwipsPerPixelY
End Sub

Private Sub Picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Dim POINT As POINTAPI
GetCursorPos POINT
LastPoint.X = POINT.X
LastPoint.Y = POINT.Y
bMoveFrom = True
End If
End Sub

Private Sub Picture1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Dim iDX As Long, iDY As Long
Dim POINT As POINTAPI
If Not bMoveFrom Then Exit Sub
GetCursorPos POINT
iDX& = (POINT.X - LastPoint.X) * iTPPX&
iDY& = (POINT.Y - LastPoint.Y) * iTPPY&
LastPoint.X = POINT.X
LastPoint.Y = POINT.Y
Picture1.Move Picture1.Left + iDX&, Picture1.Top + iDY&
End Sub

Private Sub Picture1_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
bMoveFrom = False
End Sub










( dragpicture.html )- by Paolo Puglisi - Modifica del 17/12/2023