VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Drag a form WITHOUT a title bar

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 Declarations
Private 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

Rate Drag a form WITHOUT a title bar

'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

Download this snippet    Add to My Saved Code

Drag a form WITHOUT a title bar Comments

No comments have been posted about Drag a form WITHOUT a title bar. Why not be the first to post a comment about Drag a form WITHOUT a title bar.

Post your comment

Subject:
Message:
0/1000 characters