Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving a VB window or VBA userform that doesn't have a title bar

VBA How To

Moving a VB window or VBA userform that doesn't have a title bar

by  taupirho  Posted    (Edited  )
A previous FAQ of mine shows how to remove the title bar from a userform or window. Great. But now you can't move the form/window ... or can you? Read on.

More API programming I'm afraid but the code is fairly short

Put the following code in the general declaration section

Private Declare Function ReleaseCapture Lib "user32" () As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long


Now in your form mousedown event for VB use:

Private sub form1_mousedown(ByVal Button As Integer,Byval Shift as integer,ByVal X as single,ByVal Y as Single)

Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION= 2
CALL ReleaseCapture
CALL SendMessage(me.hwnd,WM_NCLBUTTONDOWN,HTCAPTION,0)

end sub


For VBA we have to obtain the hwnd of our userform to supply as the first parameter to SendMessage. Do this with the code below.

hwnd = IIF(val(application.version) < 9,"ThunderXframe","ThunderDFrame"), Userform1.caption)
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top