Search Tools Links Login

Drag a form WITHOUT a title bar!


Visual Basic 6, or VB Classic

With this code you can easily drag a form without a titlebar.

Original Author: Dennis Wrenn

Assumptions

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

Code

'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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 94 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.