|
Move forms without using the TitleBar!This source code example allows you the ability to move a form around on the screen (using the mouse) without dragging the form's Title Bar! In order to test this example, you will need only a blank form. Start Visual Basic and select New Project. On the newly created form simply choose "View Code" and insert the following constants and declarations in the form level: Const HTCAPTION = 2 Const WM_NCLBUTTONDOWN = &HA1 Private Declare Function ReleaseCapture Lib "user32" () As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long The next order of business it to actually trap the clicking of the left mouse button over the form's client area. To do this, we will use the MouseDown event. When the event is triggered, we will verify that it was the left mouse button that triggered the event, then call the Windows API ReleaseCapture Sub followed by sending the WM_NCLBUTTONDOWN constant message to the window. Enter the code into the Form_MouseDown event as follows:
Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = 1 Then ' Checking for Left Button only
Dim ReturnVal As Long
x = ReleaseCapture()
ReturnVal = SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub
Run the project, and click the button over the form and drag that baby around! ------------------------------------------------- Original tip and project submitted by Jeff Hargett of the VB4UandMe site. Minor text editing by Burt Abreu. -------------------------------------------------
|
Quick searches: Site Search | Advanced Site Search |
|
By using this site you agree to its terms and conditions VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc. |