Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

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,
0
taylorrr
Asked:
taylorrr
  • 4
1 Solution
 
Richie_SimonettiIT OperationsCommented:
0
 
Richie_SimonettiIT OperationsCommented:
0
 
JoaTexCommented:
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.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now