devxlogo

Move a Form Without a Title Bar

Move a Form Without a Title Bar

Enter this code in a BAS module to let users move a window without a title bar:

 Declare Function ReleaseCapture Lib "user32" () As LongDeclare Function SendMessage Lib "user32" _	Alias "SendMessageA" ( _	ByVal hwnd As Long, ByVal wMsg As Long, _	ByVal wParam As Long, lParam As Any) As LongPublic Const HTCAPTION = 2Public Const WM_NCLBUTTONDOWN = &HA1

To give users a way to begin the move, place a little colored PictureBox in one corner of the form and let its MouseDown event begin the process:

 Private Sub Picture1_MouseDown(Button As _	Integer, Shift As Integer, X As Single, Y As Single)	ReleaseCapture	SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&End Sub

devx-admin

Share the Post: