'
' Do nothing if font size hasn't changed
If pfrm.FontSize <> sngOriginalFontSize Then
With pfrm
' Calculate ratios based on change in font size
sngX = .TextWidth(Spacer) / lngOldWidth
sngY = .TextHeight(Spacer) / lngOldHeight
' Resize form
lngWidth = .ScaleWidth * sngX + lngExtraWidth
lngHeight = .ScaleHeight * sngY + lngExtraHeight
' Center form if it was already centered, otherwise don't move it
If .Left <> (Screen.Width - .Width) \ 2 Then lngLeft = .Left Else lngLeft = (Screen.Width - lngWidth) \ 2
If .Top <> (Screen.Height - .Height) \ 2 Then lngTop = .Top Else lngTop = (Screen.Height - lngHeight) \ 2
.Move lngLeft, lngTop, lngWidth, lngHeight
' Identify TabIndex order
iMax = .Controls.Count - 1
End With
If iMax >= 0 Then
ReDim lngTabIndex(iMax)
For Each ctl In pfrm.Controls
' Resize lines & shapes now because they don't have a TabIndex
With ctl
Select Case TypeName(ctl)
Case "Line"
' Identify left offset (used for controls on an inactive SSTab tab)
If TypeName(.Container) = "SSTab" And .X1 < -1500 Then lngSSTab = 75000 Else lngSSTab = 0
.X1 = (.X1 + lngSSTab) * sngX - lngSSTab
.X2 = (.X2 + lngSSTab) * sngX - lngSSTab
.Y1 = .Y1 * sngY
.Y2 = .Y2 * sngY
iMax = iMax - 1
Case "Shape", "Image"
' Identify left offset (used for controls on an inactive SSTab tab)
If TypeName(.Container) = "SSTab" And .Left < -1500 Then lngSSTab = 75000 Else lngSSTab = 0
.Move (.Left + lngSSTab) * sngX - lngSSTab, .Top * sngY, .Width * sngX, .Height * sngY
iMax = iMax - 1
Case Else
On Error Resume Next
lngTabIndex(.TabIndex) = i
If Err.Number <> 0 Then iMax = iMax - 1
On Error GoTo 0
' Identify ComboBox height
If TypeOf ctl Is ComboBox And lngComboHeight = 0 Then
.FontSize = pfrm.FontSize
lngComboHeight = ctl.Height
End If
End Select
End With
i = i + 1
Next
' Identify standard textbox height now to speed up loop
If lngComboHeight = 0 Then lngComboHeight = pfrm.TextHeight(Spacer) + 4 * Screen.TwipsPerPixelY
' Iterate controls in TabIndex order
For i = 0 To iMax
Set ctl = pfrm.Controls(lngTabIndex(i))
Select Case TypeName(ctl)
Case "OptionButton", "CheckBox": strCaption = Replace(Replace(Replace(ctl.Caption, "&&", "~"), "&", ""), "~", "&")
End Select
If i <> 0 Then
Set ctlPrev = pfrm.Controls(lngTabIndex(i - 1))
Select Case TypeName(ctlPrev)
Case "OptionButton", "CheckBox": strCaptionPrev = Replace(Replace(Replace(ctlPrev.Caption, "&&", "~"), "&", ""), "~", "&")
End Select
If ctl.Tag = "Etched" Then Set ctlEtched = pfrm.Controls(lngTabIndex(i - 1))
End If
With ctl
' Identify left offset (used for controls on an inactive SSTab tab)
If TypeName(.Container) = "SSTab" And .Left < -1500 Then lngSSTab = 75000 Else lngSSTab = 0
' Identify current dimensions
lngLeft = .Left + lngSSTab
lngTop = .Top
lngWidth = .Width
lngHeight = .Height
' LEFT
Select Case .Tag
Case "Left"
Select Case TypeName(ctlPrev)
Case "OptionButton", "CheckBox": lngLeft = ctlPrev.Left + CaptionLeftOffset * Screen.TwipsPerPixelX + pfrm.TextWidth(CaptionLeftChar)
Case Else: lngLeft = ctlPrev.Left
End Select
Case "Right"
Select Case TypeName(ctlPrev)
Case "OptionButton", "CheckBox": lngLeft = ctlPrev.Left + (CaptionLeftOffset + 1) * Screen.TwipsPerPixelX + pfrm.TextWidth(strCaptionPrev) + pfrm.TextWidth(OptionSpacer)
Case Else: lngLeft = ctlPrev.Left + ctlPrev.Width + pfrm.TextWidth(Spacer)
End Select
Case "Etched": lngLeft = ctlPrev.Left + Screen.TwipsPerPixelX
Case Else: lngLeft = lngLeft * sngX
End Select
' TOP
Select Case .Tag
Case "Etched": lngTop = ctlPrev.Top + Screen.TwipsPerPixelY
Case Else: lngTop = lngTop * sngY
End Select
' WIDTH
Select Case .Tag
Case "Fixed"
Case "MultiLine": lngWidth = lngWidth * sngX
Case "Etched": lngWidth = ctlPrev.Width
Case Else
Select Case TypeName(ctl)
Case "OptionButton", "CheckBox": lngWidth = CaptionLeftOffset * Screen.TwipsPerPixelX + 2 * pfrm.TextWidth(CaptionLeftChar) + pfrm.TextWidth(strCaption)
Case "TextBox": If .MaxLength <> 0 Then lngWidth = pfrm.TextWidth("8") * (.MaxLength + 1) Else lngWidth = lngWidth * sngX
Case Else: lngWidth = lngWidth * sngX
End Select
End Select
' HEIGHT
Select Case .Tag
Case "Fixed"
Case "MultiLine": lngHeight = lngHeight * sngY
Case "Etched": lngHeight = ctlPrev.Height
Case Else
Select Case TypeName(ctl)
Case "OptionButton", "CheckBox": lngHeight = lngComboHeight
Case "ListBox"
lngLines = ctl.Height \ lngOldHeight
lngHeight = pfrm.TextHeight(Spacer) * lngLines + ctl.Height - (lngLines * lngOldHeight)
Case "TextBox": lngHeight = lngComboHeight
Case Else: lngHeight = lngHeight * sngY
End Select
End Select
' Apply new formatting
On Error Resume Next
.Font.Size = pfrm.FontSize
On Error GoTo 0
Select Case TypeName(ctl)
Case "Label"
Select Case .Tag
Case "MultiLine", "Etched"
Case Else
.AutoSize = True
lngHeight = .Height
Select Case .Alignment
Case vbRightJustify: If lngWidth < .Width Then lngLeft = lngLeft - (.Width - lngWidth)
Case vbCenter: If lngWidth < .Width Then lngLeft = lngLeft - (.Width - lngWidth) \ 2
End Select
lngWidth = .Width
End Select
.Move lngLeft, lngTop, lngWidth, lngHeight
Case "ComboBox"
lngComboHeight = .Height
.Move lngLeft, lngTop, lngWidth
Case Else
.Move lngLeft, lngTop, lngWidth, lngHeight
End Select
' Check for vertical align
If i <> 0 Then
If TypeOf ctlPrev Is Label Then
Select Case .Tag
Case "Label", "Right"
' If previous control is an Etched label, move both labels
If ctlPrev.Tag = "Etched" Then
ctlEtched.Top = ctl.Top + 3 * Screen.TwipsPerPixelY
ctlPrev.Top = ctlEtched.Top + Screen.TwipsPerPixelY
Else
ctlPrev.Top = ctl.Top + 3 * Screen.TwipsPerPixelY
End If
End Select
End If
End If
End With
Set ctl = Nothing
Next
Set ctlPrev = Nothing
Set ctlEtched = Nothing
End If
End If
' Reset ScaleMode to original settings
With pfrm
If enScaleMode = vbUser Then
.ScaleLeft = lngScaleLeft
.ScaleTop = lngScaleTop
.ScaleWidth = lngScaleWidth
.ScaleHeight = lngScaleHeight
Else
.ScaleMode = enScaleMode
End If
End With
End Sub