Drag userform around the screen without a TitleBar

Adroitking

Board Regular
Joined
Aug 12, 2004
Messages
122
I have made a very pretty userform in which I stripped off the title bar. I replaced the titlebar with an Image pasted to the userform. Is it possible for me to click on the Image and drag the userform around?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Adroitking

Board Regular
Joined
Aug 12, 2004
Messages
122
Go I figured it out...Thanks
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long 
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long 
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long 
Private Declare Function ReleaseCapture Lib "user32" () As Long 
Private Const GWL_STYLE As Long = (-16) 
Private wHandle As Long 


Private Sub CommandButton1_Click() 
Unload Me 
End Sub 


Private Sub UserForm_Initialize() 
    Dim frm As Long, frmstyle As Long 
    If Val(Application.Version) >= 9 Then 
        wHandle = FindWindow("ThunderDFrame", Me.Caption) 
    Else 
        wHandle = FindWindow("ThunderXFrame", Me.Caption) 
    End If 
    If wHandle = 0 Then Exit Sub 
    frm = GetWindowLong(wHandle, GWL_STYLE) 
    frm = frm Or &HC00000 
    SetWindowLong wHandle, -16, frmstyle 
    DrawMenuBar wHandle 
End Sub 


Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) 
   'Code to drag the form 

   If wHandle = 0 Then Exit Sub 
   If Button = 1 Then 
       ReleaseCapture 
       SendMessage wHandle, &HA1, 2, 0 
   End If 
End Sub
 

Forum statistics

Threads
1,172,139
Messages
5,879,271
Members
433,416
Latest member
montex01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top