PDA

View Full Version : Solved: Minimize/Maximize Userform



av8tordude
05-22-2009, 08:49 AM
I found this code through a search engine and was trying to revise it to fit my userform.


Dim dHeight As Double

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

Private Sub UserForm_Initialize()
dHeight = Me.Height
End

In the Enter button I put this code to minimize the userform when I click the enter button and and change the toggle button to true:


Me.Height = Me.Height * 0.25
ToggleButton1.Value = True

The 0.25 size is the size I wan the userform to be when I minimize the userform.

When the userform is minimize, I have a toggle button to maximize the userform. Unfornuately, when I click the toggle button again to minimize the userform, it doesn't minimize the userform to 0.25. It minimizes the userform to 0.50.

How can I get this code to minimize to the 0.25 size all the time?

MaximS
05-22-2009, 09:09 AM
Try that:


Private Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
Me.Height = Me.Height * 0.5
ToggleButton1.Value = False
Else
Me.Height = dHeight
End If
End Sub

av8tordude
05-22-2009, 09:21 AM
Thank you Maxim for assisting me with this coding, but put this part of the code
ToggleButton1.Value = False prevents me from minimzing or maximizing the userform at random.

av8tordude
05-22-2009, 09:39 AM
Ok...I revise the code. Could this be coded better and more effencient or is this the most effecient way to code this?

Enter Button:

Me.Height = Me.Height * 1
ToggleButton1.Value = True

Togglebotton:

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

MaximS
05-22-2009, 10:45 AM
my fault why not to try having min/max under one button.

Private Sub ToggleButton1_Click()

Dim dHeight As Double

'set true value of your userform
dHeight = 350

If ToggleButton1.Value = True Then
Me.Height = Me.Height * 0.25
ToggleButton1.Caption = "Maximize"
Else
Me.Height = dHeight
ToggleButton1.Caption = "Minimize"
End If
End Sub

av8tordude
05-22-2009, 11:00 AM
my fault why not to try having min/max under one button.

Do you mean under one command button or toggle button? I tried the command button, but the code that I found didn't seem to work well.

The formula works well. Thanks Maxim

MaximS
05-22-2009, 12:00 PM
i meant togglebutton