Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21271

Moving a Form using API Problem

$
0
0
I can move a Form (or an object such as a Picturebox) using the following

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

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

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

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?

Viewing all articles
Browse latest Browse all 21271

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>