Consulting

Results 1 to 14 of 14

Thread: Solved: UserForm change width- Left Border?

  1. #1

    Solved: UserForm change width- Left Border?

    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?

    [vba]
    Private Sub CommandButton2_Click() '
    Do While Me.Width <= 400
    Me.Width = Me.Width + 15
    Loop
    End Sub
    [/vba]
    Last edited by omnibuster; 06-12-2009 at 03:37 PM.

  2. #2
    VBAX Regular pike's Avatar
    Joined
    Dec 2007
    Location
    Alstonville, Australia
    Posts
    97
    Location
    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

  3. #3
    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.

  4. #4
    VBAX Regular pike's Avatar
    Joined
    Dec 2007
    Location
    Alstonville, Australia
    Posts
    97
    Location
    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

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try:[vba]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
    [/vba]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    You could just use one button and change the caption.......see attached:

    [VBA]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
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    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.

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    Thanks lucas.
    That way i was going.

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

  10. #10
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Quote Originally Posted by omnibuster
    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.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  11. #11
    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:
    [VBA]
    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
    [/VBA]

  12. #12
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Done the work to find it already solved, nevermind. What I did (and see attached):[vba]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

    [/vba]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  13. #13
    VBAX Regular pike's Avatar
    Joined
    Dec 2007
    Location
    Alstonville, Australia
    Posts
    97
    Location
    We done nice code - the principal is still the reference point "top" and "left" of the userform just automated

  14. #14
    Thank p45cal.
    Works great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •