by Dennis Wrenn (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating:
(6 Votes)
With this code you can easily drag a form without a titlebar.
Assumes
If you dont add If Button = 1 etc.. then if you left click, then right click the form will continue to move even though you arent clicking, its like the form is stuck to your mouse
API DeclarationsPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
'code
Private Sub FormDrag(frm As Form)
ReleaseCapture
Call SendMessage(frm.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End Sub
'usage:
'put in MouseDown even of almost anything.
'a form a label, a command button, anything will work.
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Call FormDrag(Me)
End Sub
'If you dont add If Button = 1 etc..
'then if you left click, then right
'click the form will continue to
'move even though you arent clicking,
'its like the form is stuck to your mouse