Option Explicit
Private Declare Function GetCursorPos Lib “user32” (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim bMoveForm As Boolean, LastPoint As POINTAPI
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim POINT As POINTAPI
GetCursorPos POINT
LastPoint.X = POINT.X
LastPoint.Y = POINT.Y
bMoveForm = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim iDX As Long, iDY As Long
Dim iTPPX As Long, iTPPY As Long
iTPPX& = Screen.TwipsPerPixelX
iTPPY& = Screen.TwipsPerPixelY
Dim POINT As POINTAPI
If Not bMoveForm 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
Me.Move Me.Left + iDX&, Me.Top + iDY&
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMoveForm = False
End Sub