Resize all controls when form resize

Posted on 1999-01-20
Medium Priority
Last Modified: 2010-05-03
I would like to resize all controls when the form size change, so the ratio stays the same.
The first expert who give me the working code (not just  ideas) will receive the points. I can give you more points if this is not enough.
Question by:maryjmiller
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Accepted Solution

Dalin earned 2000 total points
ID: 1469690
Try this. Let me know if you have problems.
Remember, some of the controls does not have the property like Left. you may need to modify slightly.

Option Explicit
Private InitWidth As Long       ' Form initial Size
Private InitHeight As Long

Private Sub Form_Load()
InitWidth = ScaleWidth
InitHeight = ScaleHeight
Dim Ctl As Control
' °O¿ý¨C­Ó Control ªº­ì©l¦ì¸m¡B¤j¤p¡B¦r«¬¤j¤p, ©ñ¦b Tag Äݩʤ¤
On Error Resume Next '½T«Oleft, top, width, height, TagÄݩʨS¦³¥þ¦³ªºControl
For Each Ctl In Me   '¤]¯à¥¿±`°õ¦æ
    Ctl.Tag = Ctl.Left & " " & Ctl.Top & " " & Ctl.Width & " " & Ctl.Height & " "
    Ctl.Tag = Ctl.Tag & Ctl.FontSize & " "
Next Ctl
On Error GoTo 0
End Sub

Private Sub Form_Resize()
Dim D(4) As Double
Dim I As Long
Dim TempPos As Long
Dim StartPos As Long
Dim Ctl As Control
Dim TempVisible As Boolean
Dim ScaleX As Double
Dim ScaleY As Double

ScaleX = ScaleWidth / InitWidth
ScaleY = ScaleHeight / InitHeight
On Error Resume Next
For Each Ctl In Me
    TempVisible = Ctl.Visible
    Ctl.Visible = False
    StartPos = 1
    ' Ū¨ú Control ªº­ì©l¦ì¸m¡B¤j¤p¡B¦r«¬¤j¤p
    For I = 0 To 4
        TempPos = InStr(StartPos, Ctl.Tag, " ", vbTextCompare)
        If TempPos > 0 Then
            D(I) = Mid(Ctl.Tag, StartPos, TempPos - StartPos)
            StartPos = TempPos + 1
            D(I) = 0
        End If
        ' ®Ú¾Ú¤ñ¨Ò³]©w Control ªº¦ì¸m¡B¤j¤p¡B¦r«¬¤j¤p
        Ctl.Move D(0) * ScaleX, D(1) * ScaleY, D(2) * ScaleX, D(3) * ScaleY
        'Ctl.Width = D(2) * ScaleX
        'Ctl.Height = D(3) * ScaleY
        If ScaleX < ScaleY Then
            Ctl.FontSize = D(4) * ScaleX
            Ctl.FontSize = D(4) * ScaleY
        End If
    Next I
    Ctl.Visible = TempVisible
Next Ctl
On Error GoTo 0
End Sub

Expert Comment

ID: 1469691
Good answer!

Expert Comment

ID: 1469692
Thanks, mcix.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1469693
I can't read the comments. Could you can put them in english? I can increase the points.

Expert Comment

ID: 1469694
O boy... email me at Dalin_N@MailExcite.Com

Author Comment

ID: 1469695
Thanx for all!

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

771 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