Attribute VB_Name = "ResizeControls" 'ResizeControls.bas ' ' These routines are used when resizing a form ' ' 1-10-01 by Robert Clemenzi ' ' These routines are used to control the location of (pin) UI Objects ' when the form is re-sized. ' The pin types are ' ' Right - form.width - o.left = constant ' Bottom - form.heigth - o.top = constant ' Width - form.width - o.width = constant ' Height - form.heigth - o.height = constant ' ' From the main form ' Call Init_Pin_Array first ' Call Init_Pin_UIObjects once for each object ' For each additional form ' Call Set_FormDefaults first ' Call Init_Pin_UIObjects once for each object ' ' In each form, call ResizePin_UIObjects from the Resize event ' ' The minimum form size is always enforced ' ' ' There are 2 arrays ' * Data about the forms ' * Data for each user interface component ' ' Each array element is tagged with a form name. ' This allows applications with several forms to share ' a single set of routines. ' Option Explicit Private Type T_Pin_Record FormName As String ' This allows several forms to ' share the same routines ObjectID As Object PinType As Resize_Constants ' was String offset As Long End Type Private Type T_FormDefaults_Record FormName As String ' This allows several forms to ' share the same routines Height As Long Width As Long End Type Private Pin_Array() As T_Pin_Record Private FormDefaults_Array() As T_FormDefaults_Record ' An enumeration is used instead of strings so that ' Ctrl-Enter will prompt the user with the only ' allowed values ' Too bad that there is no way to ' generate a compile-time error Enum Resize_Constants Stretch_Width Stretch_Height Pin_To_Bottom Pin_To_Right End Enum ' This must be called first in order to ' initialize the arrays ' Only the main form should call this ' Sub Init_Pin_Array(f As Form) ReDim Pin_Array(0) ' The null value has leading and trailing space ' and is never used Pin_Array(0).FormName = " Null Pin_Array Value " ReDim FormDefaults_Array(0) ' The 1st form gets its Call Set_FormDefaults(f) ' defaults set here End Sub ' The Main form should not call this ' Each additional form must call this before ' registering any objects ' Sub Set_FormDefaults(f As Form) Dim i i = UBound(FormDefaults_Array) + 1 ReDim Preserve FormDefaults_Array(i) FormDefaults_Array(i).FormName = f.Name FormDefaults_Array(i).Height = f.Height FormDefaults_Array(i).Width = f.Width End Sub ' Add objects to the array Sub Init_Pin_UIObjects(o As Object, Pin_Type As Resize_Constants) Dim xx, index index = UBound(Pin_Array) + 1 ReDim Preserve Pin_Array(index) Set Pin_Array(index).ObjectID = o Pin_Array(index).PinType = Pin_Type Pin_Array(index).FormName = o.Container.Name Select Case LCase(Pin_Type) Case Pin_To_Right '"right" xx = o.Container.Width - o.Left Case Pin_To_Bottom '"bottom" xx = o.Container.Height - o.Top Case Stretch_Width '"width" xx = o.Container.Width - o.Width Case Stretch_Height '"height" xx = o.Container.Height - o.Height Case Else End Select Pin_Array(index).offset = xx End Sub ' Reposition the known objects Sub ResizePin_UIObjects(f As Form) Dim i, xx, Fname Call Check_Min_Window_Size(f) Fname = f.Name For i = 1 To UBound(Pin_Array) If Pin_Array(i).FormName = Fname Then xx = Pin_Array(i).offset Select Case LCase(Pin_Array(i).PinType) Case Pin_To_Right '"right" Pin_Array(i).ObjectID.Left = f.Width - xx Case Pin_To_Bottom '"bottom" Pin_Array(i).ObjectID.Top = f.Height - xx Case Stretch_Width '"width" Pin_Array(i).ObjectID.Width = f.Width - xx Case Stretch_Height '"height" Pin_Array(i).ObjectID.Height = f.Height - xx Case Else End Select End If Next i End Sub ' Enforce a minimum window size Sub Check_Min_Window_Size(f As Form) Dim Default_Width, Default_Height, i For i = 1 To UBound(FormDefaults_Array) If FormDefaults_Array(i).FormName = f.Name Then Default_Width = FormDefaults_Array(i).Width Default_Height = FormDefaults_Array(i).Height End If Next i If f.Height < Default_Height Then f.Height = Default_Height If f.Width < Default_Width Then f.Width = Default_Width End Sub '--------------------------------------------------------- 'Examples ' Place this in Form_Load() ' ' Define objects which move or stretch when the form is re-sized ' Init_Pin_Array Me ' ' Init_Pin_UIObjects Directory1_UIButton, Pin_To_Right ' Init_Pin_UIObjects Directory2_UIButton, Pin_To_Right ' Init_Pin_UIObjects Directory1_UIText, Stretch_Width ' Init_Pin_UIObjects Directory2_UIText, Stretch_Width ' ' Init_Pin_UIObjects Close_UIButton, Pin_To_Bottom ' Place this in Form_Resize() ' ResizePin_UIObjects Me