Minimize button on a userform?

Ruffinshot

New Member
Joined
Jul 7, 2002
Messages
32
Is there any way to either a) put a clickable minimize button next to the close button on a userform? OR b) make the top of the userform (the caption) clickable?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
My thoughts...

Make a little button and put it wherever on the userform.

Then have the button execute a macro something to the effect of:

With UserForm1
.Height = 120
.Top = 500
.Left = 10
End With

(you'll have to fiddle with the exact numbers to make them best for your display)

Of course, you would have to put code to undo this...

For a clickable caption, you could trigger code with the setfocus event, I believe.

HTH,
Corticus
This message was edited by Corticus on 2002-07-08 12:44
 
Upvote 0
You could use this Api Calls to use the Maximize and Minimize buttons.

To use it, use the Caption of the UserForm to send the function to it (i.e, MinMax "MyUserform")

<pre>
Private Const GWL_STYLE As Long = (-16) 'The offset of a window's style
Private Const WS_MAXIMIZEBOX As Long = &H10000 'Style to add a Maximize box to the title bar
Public Const WS_MINIMIZEBOX = &H20000

Public Sub MinMax(sCaption As String)
Dim hWndForm As Long
Dim iStyle As Long

'Get handle to userform
If Val(Application.Version) < 9 Then
hWndForm = FindWindow("ThunderXFrame", sCaption) 'XL97
Else
hWndForm = FindWindow("ThunderDFrame", sCaption) 'XL2000
End If

'Get the basic window styles
iStyle = GetWindowLong(hWndForm, GWL_STYLE)

'Add maximize and minimize button
iStyle = iStyle Or WS_MAXIMIZEBOX
iStyle = iStyle Or WS_MINIMIZEBOX
'Set the basic window styles
SetWindowLong hWndForm, GWL_STYLE, iStyle
End Sub</pre>
 
Upvote 0
That code also lets you double click on the Title bar to maximize or restore it.

Also, I forgot to change the MINIMIZEBOX constant to Private, OR, you can change the other two to Public... doesn't really matter, it's just a matter of memory handling.
 
Upvote 0
Lost me here. I've never used (or needed) API calls before so I'm not quite sure where to put all this. This is adding to an existing form ("Bowser") with a couple thousand lines of code already in it, so starting from scratch isn't an option. I dropped it all in and didn't get any errors, but didn't get a minimize button either. Could someone please clarify how this goes in?
 
Upvote 0
Hi Ruffinshot

Perhaps a nice simple approach.

Add a ToggleButton to your userForm then use:


Code:
Dim dWidth As Double

Private Sub ToggleButton1_Click()
    If ToggleButton1.Value = True Then
        Me.Height = Me.Height * 0.25
    Else
       Me.Height = dWidth
    End If
End Sub


Private Sub UserForm_Initialize()
    dWidth = Me.Height
End Sub
 
Upvote 0
Out of room for buttons, at least at the top. There's 4 switches that open smaller forms within the form, a fifth that exchanges those for 4 more, several cases where it opens up to cover the whole page. (Basically, it's a 90 sheet, 3D map with a lot of search and filing functions.) In short, the only place I can put another button without re-writing the entire thing is at the bottom of the form.
 
Upvote 0
RE:In short, the only place I can put another button without re-writing the entire thing is at the bottom of the form.


If your Form is that cluttered you should think about redesigning it, or assign the code to the UserForm Double Click, or the Click or assign it to a shortcut key.
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

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
Back
Top