'To use, put the dozen or so lines below inside your form:
'
Private mobjResizer As Resizer
Private Sub Form_Resize()
mobjResizer.ResizeControls Me
End Sub
Private Sub Form_Load()
Set mobjResizer = New Resizer
mobjResizer.InitResizeArray Me
' Optional: move but don't resize the Ok button
mobjResizer.SetControlProperties "cmdOk", True, False
' Optional: resize but don't move the Close button
mobjResizer.SetControlProperties "cmdClose", False, True
End Sub
'===========================================================
' Put everything below into a class module named "Resizer"
Private Type CtrlProportions
Name As String
Move As Boolean
Resize As Boolean
HeightProportions As Single
WidthProportions As Single
TopProportions As Single
LeftProportions As Single
End Type
Private mProportionsArray() As CtrlProportions
Public Sub InitResizeArray(objForm As Form)
Dim I As Integer
Dim ObjLeft As Long
Dim ObjParentTyp As String
Dim LeftOffset As Long
On Error Resume Next
ReDim mProportionsArray(0 To objForm.Controls.Count - 1)
For I = 0 To objForm.Controls.Count - 1
With mProportionsArray(I)
.Name = objForm.Controls(I).Name
.Move = True
.Resize = True
.HeightProportions = objForm.Controls(I).Height / objForm.ScaleHeight
.WidthProportions = objForm.Controls(I).Width / objForm.ScaleWidth
.TopProportions = objForm.Controls(I).Top / objForm.ScaleHeight
' Have to be a little careful with .Left here. Controls on an SSTab
' control have -75000 added to their .Left prop to make them invisible.
LeftOffset = 0
ObjLeft = objForm.Controls(I).Left
ObjParentTyp = TypeName(objForm.Controls(I).Container)
If ObjParentTyp = "SSTab" And ObjLeft < 0 Then LeftOffset = 75000
.LeftProportions = (ObjLeft + LeftOffset) / objForm.ScaleWidth
End With
Next I
End Sub
Public Sub ResizeControls(objForm As Form)
On Error Resume Next
Dim I As Integer
Dim ObjParentTyp As String
Dim LeftOffset As Long
For I = 0 To objForm.Controls.Count - 1
With mProportionsArray(I)
' move and resize objcontrols
If .Move Then
LeftOffset = 0
ObjParentTyp = TypeName(objForm.Controls(I).Container)
If ObjParentTyp = "SSTab" And objForm.Controls(I).Left < 0 Then LeftOffset = 75000
objForm.Controls(I).Left = .LeftProportions * objForm.ScaleWidth - LeftOffset
objForm.Controls(I).Top = .TopProportions * objForm.ScaleHeight
End If
If .Resize Then
objForm.Controls(I).Width = .WidthProportions * objForm.ScaleWidth
objForm.Controls(I).Height = .HeightProportions * objForm.ScaleHeight
End If
End With
Next I
End Sub
Public Sub SetControlProperties(strName As String, flgMove As Boolean, flgResize As Boolean)
Dim I As Integer
For I = 0 To UBound(mProportionsArray())
If mProportionsArray(I).Name = strName Then
mProportionsArray(I).Move = flgMove
mProportionsArray(I).Resize = flgResize
End If
Next I
End Sub