Resizing controls in VB6

Posted on 2006-04-20
Last Modified: 2010-04-07
How can I resize a control in my Form in VB6 so that the control resizes automatically when the user resizes the Form? It would be something similar to the Anchoring property in .Net.

Question by:MyersA
    LVL 69

    Expert Comment

    by:Éric Moreau
    Hi MyersA,


    LVL 2

    Author Comment


    Is it possible to do this without purchasing 3rd party components? Can I write code that does this?

    LVL 69

    Expert Comment

    by:Éric Moreau
    It is possible. be ready to write a lot of code.

    When I was doing VB6 apps, I was trying to put some controls into groupbox. When a form was resized, the groupbox was often following a margin. It was easier then having to move each control. A grid was also in the center of the form which was resized to fit the empty space.
    LVL 28

    Accepted Solution

    You could try downloading this module and adding it to your project:

    to use,just add the following to each form:

    Private Sub Form_Resize()
      ResizeFormFor Me
    End Sub

    Also, check this out:
    LVL 6

    Assisted Solution

    Hello Sir,

      Check the following site if it is of any use to you.

    with regards,
    LVL 4

    Expert Comment


    i wrote two routines

    one to resize control
    one to attach to the right of a window a control

    here some sample

    Private Sub Form_Resize()

    'resizes fragenerales in that proportion
    'dont bother if the form is minimized
        ResizeCTRL Me, Me.fraGenerales, 3, 16, 4000, 4000

    End Sub

    'here the routines

    Sub ResizeCTRL(ReferralControl As Object, Ctrl As Control, WidthUnits As Long, HeightUnits As Long, Optional MinWidth As Long, Optional MinHeight As Long, Optional AdjustLeftPosUnits As Long, Optional adjustTopPosUnits As Long)
        Dim t As Long
        'If IsMissing(ReferralControl) Then ReferralControl = Ctrl.Container
        If IsMissing(MinWidth) Then MinWidth = 0
        If IsMissing(MinHeight) Then MinHeight = 0
        If IsMissing(AdjustLeftPosUnits) Then AdjustLeftPosUnits = -1
        If IsMissing(adjustTopPosUnits) Then adjustTopPosUnits = -1
        If WidthUnits <> -1 Then
            If ReferralControl.Width > MinWidth Then
                Ctrl.Width = ReferralControl.Width - (120 * WidthUnits)
            End If
        End If
        If AdjustLeftPosUnits <> -1 And AdjustLeftPosUnits <> 0 Then
            If ReferralControl.Width > MinWidth Then
            'If t > MinWidth Then
                Ctrl.Left = ReferralControl.Width - (120 * AdjustLeftPosUnits)
            End If
        End If
        If HeightUnits <> -1 Then
            t = ReferralControl.Height - (120 * HeightUnits)
            If t > 0 + MinHeight Then
                Ctrl.Height = t
            End If
        End If
        If adjustTopPosUnits <> -1 And adjustTopPosUnits <> 0 Then
            t = ReferralControl.Height - (120 * adjustTopPosUnits)
            If t > MinHeight Then
                Ctrl.Top = t
            End If
        End If
    End Sub

    Sub AttachToRight(F As Form, C As Control, AdditionalUnits As Long, MinWidth As Long)

        If F.Width > MinWidth Then
            C.Left = F.Width - (C.Width + ((2 + AdditionalUnits) * 120))
        End If
    End Sub

    okay maybe the routine is too big, but the coding is a snap and does not get too much resources at runtime.


    hope this helps

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now