Solved

Resize all controls when form resize

Posted on 1999-01-20
6
269 Views
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.
Thanks
0
Comment
Question by:maryjmiller
  • 3
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
Dalin earned 500 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.
Regards
Dalin

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
        Else
            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
        Else
            Ctl.FontSize = D(4) * ScaleY
        End If
    Next I
    Ctl.Visible = TempVisible
Next Ctl
On Error GoTo 0
End Sub
0
 
LVL 4

Expert Comment

by:mcix
ID: 1469691
Good answer!
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1469692
Thanks, mcix.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:maryjmiller
ID: 1469693
indeed!
I can't read the comments. Could you can put them in english? I can increase the points.
Thanks
0
 
LVL 9

Expert Comment

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

Author Comment

by:maryjmiller
ID: 1469695
Thanx for all!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

706 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

20 Experts available now in Live!

Get 1:1 Help Now