How to Move a Border-less Form or Control in VB6/Visual Basic 6


The following codes allows you to drag or move a border-less Form or Control in Visual Basic 6. This also works on other controls like Label, Image or Picture Box. You can also move or drag a control inside a form.

Copy and Paste the code below in a Standard Module.
 Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long  
 Declare Sub ReleaseCapture Lib "user32" ()  
 Public Const WM_NCLBUTTONDOWN = &HA1  
 Public Const HTCAPTION = 2

Then Copy and Paste the code below on a Form or Controls MouseDown Event.
 Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)  
     Dim ReturnValue As Long  
     If Button = 1 Then  
     Call ReleaseCapture  
     ReturnValue = SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)  
     End If  
 End Sub

You should be able to move the form by holding the mouse button then drag.

Comments

Popular posts from this blog

How to Create a Configuration.INI Files in VB6

How to Make Windows Form Transparent using Visual Basic 6/VB6

How to Set Windows Form Always on Top of Other Applications in VB6