Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLet the user move a form that has no title bar or borders in Visual Basic .NET
DescriptionThis example shows how to let the user move a form that has no title bar or borders in Visual Basic .NET.
Keywordsmove form, title bar, WM_NCLBUTTONDOWN, HTCAPTION, SendMessage, DefWndProc, VB.NET
CategoriesAPI, VB.NET
 
When the user presses the left mouse button down on the lblDragMe control, the MouseDown event handler executes. It sets the control's Capture property to False to release the mouse capture that was started by pressing the mouse button down.

Next the program makes a Message with message WM_NCLBUTTONDOWN and wParam set to HTCAPTION, and calls the form's DefWndProc method to process the message. This is the same message Windows sends to the form when the user presses the mouse down over the form's title bar so it starts a form move.

 
' On left button, let the user drag the form.
Private Sub lblDragMe_MouseDown(...) Handles _
    lblDragMe.MouseDown
    If e.Button = MouseButtons.Left Then
        lblDragMe.Capture = False

        ' Create and send a WM_NCLBUTTONDOWN message.
        Const WM_NCLBUTTONDOWN As Integer = &HA1S
        Const HTCAPTION As Integer = 2
        Dim msg As Message = _
            Message.Create(Me.Handle, WM_NCLBUTTONDOWN, _
                New IntPtr(HTCAPTION), IntPtr.Zero)
        Me.DefWndProc(msg)
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated