How to reposition and resize all the controls on a form whenever the form is resized.
Posted on July 2, 2011
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 'Forms - How to reposition and resize all the controls on a form whenever the form is resized. 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 |