Link to home
Start Free TrialLog in
Avatar of taylorrr
taylorrr

asked on

Resizing controls on a form...

Hello,

I was wondering if anyone has got some code that will resize controls on a form when the form itself is
resized.

thx,
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

ASKER CERTIFIED SOLUTION
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JoaTex
JoaTex

Hi
Open a form and put some controls on it.
Open a Module and put the code module on It.
Put the Code in form Code.
Run project and wash all the controls.

Module:

Option Explicit

Type ScaleStruct
      Top As Integer
      Left As Integer
      Width As Integer
      Height As Integer
      ParentHeight As Integer
      ParentWidth As Integer
      FontSize As Integer
End Type

Global Ctrl() As ScaleStruct

Code:

Option Explicit
Dim N

Private Sub Form_Load()
      On Error Resume Next
      ReDim Ctrl(0 To Controls.Count - 1)
      For N = 0 To Controls.Count - 1
            Ctrl(N).Top = Controls(N).Top
            Ctrl(N).Left = Controls(N).Left
            Ctrl(N).Width = Controls(N).Width
            Ctrl(N).Height = Controls(N).Height
            Ctrl(N).ParentHeight = Controls(N).Parent.ScaleHeight
            Ctrl(N).ParentWidth = Controls(N).Parent.ScaleWidth
            Ctrl(N).FontSize = Controls(N).FontSize
      Next N
      Me.Top = Screen.Height / 2 - Me.Height / 2
      Me.Left = Screen.Width / 2 - Me.Width / 2
End Sub

Private Sub Form_Resize()
      On Error Resume Next
      For N = 0 To Controls.Count - 1
            Controls(N).Visible = False
            Controls(N).Top = Ctrl(N).Top * (Controls(N).Parent.ScaleHeight / Ctrl(N).ParentHeight)
            Controls(N).Left = Ctrl(N).Left * (Controls(N).Parent.ScaleWidth / Ctrl(N).ParentWidth)
            Controls(N).Width = Ctrl(N).Width * (Controls(N).Parent.ScaleWidth / Ctrl(N).ParentWidth)
            Controls(N).Height = Ctrl(N).Height * (Controls(N).Parent.ScaleHeight / Ctrl(N).ParentHeight)
            Controls(N).FontSize = Ctrl(N).FontSize * (Controls(N).Parent.ScaleHeight / Ctrl(N).ParentHeight)
            If Controls(N).FontSize < 4 Then Controls(N).FontSize = 4
            Controls(N).Visible = True
      Next N
End Sub

Hope it Suites you.