Attribute VB_Name = "ModuleControlAnchor" Option Explicit 'AnchorModule SeabrookStan 2019 'Place the following one line of code in Form - Sub Form_Resize(). ' Anchor ControlName, AnchorTop, AnchorLeft, AnchorRight, AnchorBottom (as Boolean) Enum AnchorSide AnchorNone AnchorLeft AnchorTop AnchorTopLeft AnchorRight AnchorLeftRight 'StretchX AnchorTopRight 'same as AnchorRight only AnchorTopLeftRight 'StretchX AnchorBottom AnchorBottomLeft AnchorTopBottom 'StretchY AnchorTopBottomLeft 'StretchY AnchorBottomRight AnchorBottomLeftRight 'StretchX AnchorTopBottomRight 'StretchY AnchorTopBottomLeftRight ' StretchXY End Enum Type TANCH Name As String DL As Long DT As Long DB As Long DR As Long End Type Dim ctlAnchors() As TANCH Function IsControlArray(Ctl As Object) As String On Error Resume Next IsControlArray = Ctl.Index End Function Function IsInitialized() As Boolean On Error Resume Next IsInitialized = IIf(UBound(ctlAnchors) >= 0, True, False) End Function Public Sub Anchor(Ctl As Control, Optional acrSide As AnchorSide = AnchorNone) Dim ctlExists As Boolean Dim strCtlName As String 'name of the form+control+index strCtlName = Ctl.Parent.Name & Ctl.Name & IsControlArray(Ctl) Dim i As Integer If Not IsInitialized Then i = 0 Else For i = 0 To UBound(ctlAnchors) If ctlAnchors(i).Name = strCtlName Then ctlExists = True Exit For 'save i index End If Next End If If Not ctlExists Then ReDim Preserve ctlAnchors(i) ctlAnchors(i).Name = strCtlName If (acrSide And AnchorRight) Then ctlAnchors(i).DR = Ctl.container.Width - Ctl.Left - Ctl.Width If (acrSide And AnchorBottom) Then ctlAnchors(i).DB = Ctl.container.Height - Ctl.Top - Ctl.Height If Not (acrSide And AnchorTop) Then ctlAnchors(i).DT = Ctl.container.Height - Ctl.Top If Not (acrSide And AnchorLeft) Then ctlAnchors(i).DL = Ctl.container.Width - Ctl.Left End If Dim CW As Long, CH As Long CW = Ctl.container.Width 'Determine Object Container size CH = Ctl.container.Height If (acrSide And AnchorRight) Then 'Now move the control's sides to follow movement of Form sides If (acrSide And AnchorLeft) Then 'StretchX Ctl.Width = IIf(CW - Ctl.Left - ctlAnchors(i).DR > 0, CW - Ctl.Left - ctlAnchors(i).DR, 0) Else Ctl.Left = Ctl.container.Width - ctlAnchors(i).DL End If End If If (acrSide And AnchorBottom) Then If (acrSide And AnchorTop) Then 'StretchY Ctl.Height = IIf(CH - Ctl.Top - ctlAnchors(i).DB > 0, CH - Ctl.Top - ctlAnchors(i).DB, 0) Else Ctl.Top = Ctl.container.Height - ctlAnchors(i).DT End If End If End Sub