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
 
 
 
 
 
TitleMove a form using the arrow keys when the user right clicks its border
Keywordsmove form, drag, border, right click
CategoriesAPI
 
By Michael Rosquist.

Subclass the form and look for the WM_NCRBUTTONDOWN message. When the wParam indicates a border mouse down, send the form the WM_SYSCOMMAND message with the SC_MOVE parameter to begin a form move. Call the form's original WindowProc to process the message only if the code doesn't do this move.

 
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg _
    As Long, ByVal wParam As Long, ByVal lParam As Long) As _
    Long
Static num As Long

Const WM_NCRBUTTONDOWN = &HA4
Const WM_NCLBUTTONDOWN = &HA1
Const WM_SYSCOMMAND = &H112
Const SC_MOVE = &HF010&
Const HTBORDER = 18
Const HTBOTTOM = 15
Const HTBOTTOMLEFT = 16
Const HTBOTTOMRIGHT = 17
Const HTCAPTION = 2
Const HTCLOSE = 20
Const HTGROWBOX = 4
Const HTLEFT = 10
Const HTMAXBUTTON = 9
Const HTMINBUTTON = 8
Const HTRIGHT = 11
Const HTSYSMENU = 3
Const HTTOP = 12
Const HTTOPLEFT = 13
Const HTTOPRIGHT = 14

Dim skip_it As Boolean

    If msg = WM_NCRBUTTONDOWN Then
        Select Case wParam
            Case HTBORDER, HTBOTTOM, _
              HTBOTTOMLEFT, HTBOTTOMRIGHT, _
              HTLEFT, HTRIGHT, HTTOP, _
              HTTOPLEFT, HTTOPRIGHT, HTGROWBOX
                ' Move the form.
                SendMessage hwnd, WM_SYSCOMMAND, SC_MOVE, _
                    ByVal 0&
                skip_it = True
        End Select
    End If
    num = num + 1

    ' Call the original WindowProc.
    If Not skip_it Then
        NewWindowProc = CallWindowProc( _
            OldWindowProc, hwnd, msg, wParam, _
            lParam)
    End If
End Function
 
When you right click the form's border, you can use the arrow keys. After you use an arrow key, you can also move the form with the mouse (at least on my system).
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated