Home > How-To Library > Forms

How to reposition and resize all the controls on a form whenever the form is resized.

**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * ****************************************************************
Private Type CtrlProportions HeightProportions As Single WidthProportions As Single TopProportions As Single LeftProportions As Single End Type Dim ProportionsArray() As CtrlProportions Sub InitResizeArray() On Error Resume Next Dim I As Integer ReDim ProportionsArray(0 To Controls.Count - 1) For I = 0 To Controls.Count - 1 With ProportionsArray(I) .HeightProportions = Controls(I).Height / ScaleHeight .WidthProportions = Controls(I).Width / ScaleWidth .TopProportions = Controls(I).Top / ScaleHeight .LeftProportions = Controls(I).Left / ScaleWidth End With Next I End Sub Sub ResizeControls() On Error Resume Next Dim I As Integer For I = 0 To Controls.Count - 1 With ProportionsArray(I) ' move and resize controls Me.Controls(I).Move .LeftProportions * ScaleWidth, .TopProportions * ScaleHeight, .HeightProportions _ * ScaleHeight, .WidthProportions * ScaleWidth End With Next I End Sub 'Form initialize event Private Sub Form_Initialize() InitResizeArray End Sub 'Form resize event Sub Form_Resize() ResizeControls End Sub

If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.