PDA

View Full Version : Solved: UserForm change width- Left Border?



omnibuster
06-12-2009, 02:26 PM
On a UserForm there are 2 button. Normal & resize Userform.
I would like to change the width of the UserForm left side (border) not the right side.
How to do this?


Private Sub CommandButton2_Click() '
Do While Me.Width <= 400
Me.Width = Me.Width + 15
Loop
End Sub

pike
06-12-2009, 07:05 PM
omnibuster
change the userform start up position to manual
And add start position for Position 'Left" and "top"
then add the new position to code when resizing
regards pike

omnibuster
06-13-2009, 01:02 AM
Maybe i dont understand exactly what you mean, but looks like simple position Userform-left,right,top...when userform activate i.e. position all userform.

I wish resize only right border for userform.

pike
06-13-2009, 01:53 AM
Didnt explan that very well

The user form size is based on the top left hand corner,its refence point
since the default for the userform is in the centre, when you run your resize code it resizes from the refernce point to the right.
what you need to do is set the start position to manual and enter values for left and top. the start point reference

Also note the left values for the commandbuttons and controls


With userform1
.left = "start point" - 15
.CommandButton1.Left = 15 + "noted value"
End With

its easier to go with the flow and expand right
hope it helps

p45cal
06-13-2009, 06:04 AM
try:Private Sub CommandButton2_Click() '
Do While Me.Width <= 400
Me.Width = Me.Width + 15
Me.Left = Me.Left - 15

Loop
End Sub
Private Sub CommandButton5_Click() '
Do While Me.Width >= 310
Me.Width = Me.Width - 15
Me.Left = Me.Left + 15
Loop
End Sub

lucas
06-13-2009, 09:36 AM
You could just use one button and change the caption.......see attached:

Option Explicit
Private Sub CommandButton2_Click() '
With CommandButton2
If .Caption = "Show" Then
Do While Me.Width <= 400
Me.Width = Me.Width + 15
Me.Left = Me.Left - 15
DoEvents
Loop
.Caption = "Hide"
Else
Do While Me.Width >= 310
Me.Width = Me.Width - 15
Me.Left = Me.Left + 15
DoEvents
Loop
.Caption = "Show"
End If
End With
End Sub
Private Sub UserForm_Initialize()
With Me
.Width = 300

End With
With CommandButton2
' .Top = 132
' .Left = 28
' .Width = 120
' .Height = 20
.Caption = "Show"
End With
End Sub

omnibuster
06-13-2009, 11:49 AM
Thanks ALL for help, but this not what i need.
All this ways operating with RightBorder in Userform, but i wish moove Left border.
In attachment file i need hide ListBox1 with mooving Left border.
Simple: ListBox1.Visible=False not that what i need.

lucas
06-13-2009, 01:29 PM
Well, sometimes there is such a thing as asking the impossible. Looks like moving your listboxes to the right side and buttons to the left would work. Just a simple layout change, right?

omnibuster
06-13-2009, 01:51 PM
Thanks lucas.
That way i was going.

Command like : Me.Right = Me.Right +/- n dont exsist.

lucas
06-13-2009, 02:49 PM
Thanks lucas.
That way i was going.

Command like : Me.Right = Me.Right +/- n dont exsist.

If you had intellisense on in your vb editor you would see that there is a .left and a .righttoleft but the righttoleft has to do with lettering from left to right or right to left according to country. There is no .right value.

I'm not saying it's impossible and I hope someone comes along to show us a way to do it. I'm just saying that often when you hit a brick wall like this it just makes more sense to adjust your layout to accomplish your goal. There are many ways to skin a cat.

omnibuster
06-13-2009, 03:07 PM
Thanks lucas.
I found too this: ".righttoleft" but my knowlege vba bad.

Lucas wrote:

I hope someone comes along to show us a way to do it.


I hope too.

If somebody needs: buttons dont moove:
I found this:

Dim cnt As Control

For Each cnt In Me.Controls
If cnt.Left + cnt.Width > Me.ScrollWidth Then
Me.ScrollWidth = cnt.Left + cnt.Width
End If
If cnt.Top + cnt.Height > Me.ScrollHeight Then
Me.ScrollHeight = cnt.Top + cnt.Height
End If
Next
Do While Me.Width >= 310
Me.Width = Me.Width - 15
Loop
End Sub

p45cal
06-13-2009, 04:08 PM
Done the work to find it already solved, nevermind. What I did (and see attached):Private Sub CommandButton2_Click() '
Dim ctrl
If CommandButton2.Caption = "Show" Then
Do While Me.Width <= 300
Me.Width = Me.Width + 15
Me.Left = Me.Left - 15
For Each ctrl In Me.Controls
ctrl.Left = ctrl.Left + 15
Next ctrl
Loop
CommandButton2.Caption = "Hide"
Else
Do While Me.Width >= 210
Me.Width = Me.Width - 15
Me.Left = Me.Left + 15
For Each ctrl In Me.Controls
ctrl.Left = ctrl.Left - 15
Next ctrl
Loop
CommandButton2.Caption = "Show"
End If
End Sub



Private Sub UserForm_Initialize()
With Me
.Width = 300

End With
With CommandButton2
.Top = 130
.Left = 220
.Width = 60
.Height = 25
.Caption = "Hide"
End With
End Sub

pike
06-13-2009, 05:11 PM
We done nice code - the principal is still the reference point "top" and "left" of the userform just automated

omnibuster
06-14-2009, 12:46 AM
Thank p45cal.
Works great.