Solved

Resize all controls when form resize

Posted on 1999-01-20
6
272 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

867 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

24 Experts available now in Live!

Get 1:1 Help Now