Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9162807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:18:03+00:00 2026-06-17T14:18:03+00:00

I have been trying to write some code to handle resizing & moving controls

  • 0

I have been trying to write some code to handle resizing & moving controls when the form is resized.

My approach is to create a Dictionary object for each Control dimension that needs to be anchored (i.e. top/left/width/height) with the key being the control name and anchor dimension (e.g. lstAccounts_Height) and to add these to a form-level Collection. On the form Resize event the Collection is iterated through, and each Control adjusted as necessary.

The routine to add controls:

Private Sub AddFormResizeControl(ControlName As String, _
                                 Dimension As String)

Dim strKey                      As String
Dim sngValue                    As Single
Dim dictCtrl                    As Dictionary

    strKey = ControlName & "_" & Dimension

    Select Case Dimension
        Case "Left": sngValue = Controls(ControlName).Left
        Case "Top": sngValue = Controls(ControlName).Top
        Case "Width": sngValue = Controls(ControlName).Width
        Case "Height": sngValue = Controls(ControlName).Height
    End Select

    Set dictCtrl = New Dictionary
    dictCtrl.Add strKey, sngValue

    If colResizeControls Is Nothing Then _
        Set colResizeControls = New Collection
    colResizeControls.Add dictCtrl, strKey

End Sub

And adding the controls in the Initialize event:

AddFormResizeControl "lst_AccountSelection", "Width"
AddFormResizeControl "lst_AccountSelection", "Height"
AddFormResizeControl "cmd_Cancel", "Left"
AddFormResizeControl "cmd_Cancel", "Top"
AddFormResizeControl "cmd_Confirm", "Left"
AddFormResizeControl "cmd_Confirm", "Top"

And the Resize event:

Private Sub UserForm_Resize()

Dim sngHeightAdjust             As Single
Dim sngWidthAdjust              As Single

Dim dict                        As Dictionary
Dim strCtrl                     As String

Dim ctrl                        As Control
Dim strDimension                As String

    If Me.Width < sngFormMinimumWidth Then Me.Width = sngFormMinimumWidth
    If Me.Height < sngFormMinimumHeight Then Me.Height = sngFormMinimumHeight

    sngHeightAdjust = (Me.Height - 4.5) - sngFormMinimumHeight
    sngWidthAdjust = (Me.Width - 4.5) - sngFormMinimumWidth

    If Not colResizeControls Is Nothing Then
        For Each dict In colResizeControls
            strCtrl = dict.Keys(0)
            Set ctrl = Controls(Left(strCtrl, InStrRev(strCtrl, "_") - 1))
            If Right(strCtrl, 5) = "_Left" Then
                ctrl.Left = dict.Item(strCtrl) + sngWidthAdjust
            ElseIf Right(strCtrl, 4) = "_Top" Then
                ctrl.Top = dict.Item(strCtrl) + sngHeightAdjust
            ElseIf Right(strCtrl, 6) = "_Width" Then
                ctrl.Width = dict.Item(strCtrl) + sngWidthAdjust
            ElseIf Right(strCtrl, 7) = "_Height" Then
                ctrl.Height = dict.Item(strCtrl) + sngHeightAdjust
            End If
        Next dict
    End If

End Sub

The problem I am facing is that there is a small “jump” on the first move event, and consequently the runtime controls are not quite aligned as they at design-time. I have tried to counter this effect by changing the returned height and width for the form by 4.5, which does help.

The sngFormMinimumHeight and sngFormMinimumWidth are set as the starting width/height or the form in the Initialize event, and I am using Chip Pearson’s code to make the form resizeable.

I’m guessing that there are some kind of borders on the form which need to be adjusted for (hence the 4.5s helping the issue) – can anyone explain what values I need to adjust by?

Resolution Thanks to the link provided by BonCodigo, the issue is now resolved – I was referring to Me.Height and Me.Width when I should have been referring to Me.InsideHeight and Me.InsideWidth. I now do not need the adjustment of 4.5 and the “jump” is now gone

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:18:04+00:00Added an answer on June 17, 2026 at 2:18 pm

    You may try to change both Anchor and Dock properties of the controls and they should automatically resize with their parent containers (perhaps a panel).

    • Following reference is in MS Access, you could adapt it though: http://www.fmsinc.com/MicrosoftAccess/controls/components/form-resizer/index.html

    • Resizer class and application from AndyPope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to write some code in Scala to read a file
I have been trying to write some code to find the average of numbers
I have recently been trying ot write code to add and delete content form
I have been trying to write some code that asks the user for several
i have been trying to write a program in python to read two text
I have been trying to write a bare-bones ping scanner using Perl for internal
I have been trying to write an image on a layer using Quartz but
I have been trying to write my own diff3 wrap script for SVN and
I have been trying to write a regex that will remove whitespace following a
I have been trying to write a custom .screenrc file TEST as follows startup_message

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.