I can move a Form (or an object such as a Picturebox) using the following
However, it does not fire the MouseUp event when I release the mouse.
If I mouse down/mouse up it will fire the MouseUp because I'm not moving the Form.
I also have this method
This one will fire the MouseUp when I release the mouse. However, it's way too slow because as I move the Form around it smears itself which is totally unacceptable not to mention messy.
Is there anyway to move the Form and have it like it does in the first example and still fire the MouseUp when I release the mouse?
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
MsgBox "Form_MouseUp"
End If
End Sub
If I mouse down/mouse up it will fire the MouseUp because I'm not moving the Form.
I also have this method
Code:
Option Explicit
Dim lngXpos As Long
Dim lngYpos As Long
Dim lngXleft As Long
Dim lngYtop As Long
Dim flgDown As Boolean
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
lngXpos = X: lngYpos = Y
lngXleft = Left: lngYtop = Top
flgDown = True
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton And flgDown = True Then
Move Left + X - lngXpos, Top + Y - lngYpos
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
flgDown = False
End Sub
Is there anyway to move the Form and have it like it does in the first example and still fire the MouseUp when I release the mouse?