Results 1 to 6 of 6

Thread: Resizing forms and controls in vb

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2014
    Posts
    9

    Resizing forms and controls in vb

    Hi

    I am trying to dynamically resize my form and controls

    I can get most of it, except for Group boxes within group boxes and their controls

    Please see the attached pics of normal vs maximised and the code below that does this

    As you can see, in the maximised state it doesn't resize all the smaller group boxes or their controls


    Dim CuRWidth As Integer = Me.Width
    Dim CuRHeight As Integer = Me.Height

    Private Sub frmBasketballStats_Resize(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Resize

    Dim RatioHeight As Double = (Me.Height - CuRHeight) / CuRHeight
    Dim RatioWidth As Double = (Me.Width - CuRWidth) / CuRWidth

    For Each Ctrl As Control In Controls
    Ctrl.Width += Ctrl.Width * RatioWidth
    Ctrl.Left += Ctrl.Left * RatioWidth
    Ctrl.Top += Ctrl.Top * RatioHeight
    Ctrl.Height += Ctrl.Height * RatioHeight

    Next

    CuRWidth = Me.Width
    CuRHeight = Me.Height

    End Sub


    Any help will be apreciated

    Thankyou

    Andrew
    Attached Images Attached Images   

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: Resizing forms and controls in vb

    You almost certainly don't need any code at all. Follow the CodeBank link in my signature below and check out my thread on the Anchor & Dock properties. It looks to me like what you should be doing is first designing a user control to represent a single player. That user control would contain a TableLayoutPanel that would contain the six GroupBoxes and then the other controls below that. You would set the Dock and Anchor properties of those child controls so that one player would resize as desired. On your form you would then add another TableLayoutPanel and add eight instances of your user control to it and then set the Dock and Anchor properties of those appropriately. Everything will then happen automatically, with no code required from you.

  3. #3

    Thread Starter
    Registered User
    Join Date
    Jul 2014
    Posts
    9

    Re: Resizing forms and controls in vb

    Hi, so there's no way I can simply fix what I have here ?

    Code attached

    Thank you

    Andrew

    Attachment 156401
    Attached Files Attached Files

  4. #4

    Thread Starter
    Registered User
    Join Date
    Jul 2014
    Posts
    9

    Re: Resizing forms and controls in vb

    Thanks for this, I done as you said and works well

    The only issue I have is the + - buttons not resizing, I have them left and right Anchored, they just spread out not resize (proportionately)
    Apart from that looks great

    Thankyou
    Andrew

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: Resizing forms and controls in vb

    Quote Originally Posted by beiag005 View Post
    Thanks for this, I done as you said and works well

    The only issue I have is the + - buttons not resizing, I have them left and right Anchored, they just spread out not resize (proportionately)
    Apart from that looks great

    Thankyou
    Andrew
    Sounds like a job for a TableLayoutPanel again. Each TLP would have one row and two columns of 50% width each. You'd then set Dock to Fill for each Button. The TLP would be Anchored to all sides of its parent GroupBox. As the GroupBox grew and shrank, so would the TLP and so would the Buttons.

  6. #6
    Addicted Member
    Join Date
    May 2017
    Location
    Italy
    Posts
    170

    Re: Resizing forms and controls in vb

    Quote Originally Posted by jmcilhinney View Post
    You almost certainly don't need any code at all. Follow the CodeBank link in my signature below and check out my thread on the Anchor & Dock properties. .
    Thanks You, but I think you need to update the code as follows
    Code:
            Label1.Anchor = AnchorStyles.Top Or AnchorStyles.Left

Posting Permissions

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



Click Here to Expand Forum to Full Width