Option expedition
'ness, ALSO FONTS Are Resize
Public ResizeFont As Boolean
'ness True, Form's Height / Width Ratio Is Preserved
Public Keepratio As Boolean
Private Type Tcontrolinfo
Ctrl As Control
Left as single
Top as single
Width as single
Height As Single
FONTSIZE As Single
End Type
'this Array Holds the Original Position
'And Size of All Controls on Parent Form
DIM controls () as tcontrolinfo
'a Reference to the Parent Form
Private Withevents ParentForm As Form
'Parent Form's Size At Load Time
Private ParentWidth as Single
Private Parentheight As Single
'Ratio of Original HEIGHT / WIDTH
Private HeightWidthratio As Single
PRIVATE SUB PARENTFORM_LOAD ()
'The ParentWidth Variable Works as a flag
ParentWidth = 0
'Save Original Ratio
Heightwidthratio = Parentform.height / ParentForm.width
End Sub
Private sub UserControl_readproperties (Propbag As Propertybag)
ResizeFont = Propag.readproperty ("Resizefont", _
False)
Keepratio = Propag.readproperty ("Keepratio", _
False)
If Ambient.usermode = false kil
'Store a Reference to the Parent Form and
'Start Receiving Events
Set ParentForm = PARENT
End Sub
Private sub UserControl_WriteProperties (Propbag As Propertybag)
Propbag.writeproperty "Resizefont", ResizeFont, _
False
Propbag.WriteProperty "Keepratio", Keepratio, _
False
End Sub
Private sub UserControl_resize ()
'Refuse to Resize
Image1.move 0, 0
UserControl.width = image1.width
UserControl.height = image1.height
End Sub
'TRAP THE PARENT FORM's Resize Event
'this incrude the very first resize es
'That Occurs Soon After Form's loadPrivate sub parentform_resize ()
IF pentwidth = 0 Then Rebuild
Else
Refresh
END IF
End Sub
'Save Size and Position of All Controls on Parent Form
'You Should Manually Invoke this Method Each Time you
'Add A New Control to the Form
"THROUGH LOAD METHOD OF A Control Array
SUB rebuild ()
'Rebuild the Internal Table
DIM I AS INTEGER, CTRL AS Control
'this is Necessary for Controls That Don't Support
'All Properties (E.G. Timer Controls)
ON Error ResMe next
If Ambient.usermode = false kil
'save a reason to the Parent Form
'and its initial size
SET PARENTFORM = UserControl.Parent
ParentWidth = ParentForm.scalewidth
Parentheight = ParentForm.scaleHeight
'Read The Position of All Controls on The Parent Form
Redim Controls (Parentform.Controls.count - 1) _
As tcontrolinfo
For i = 0 to Parentform.Controls.count? 1
Set Ctrl = Parentform.Controls (i)
WITH Controls (i)
Set .ctrl = ctrl
.Left = ctrl.Left
.Top = ctrl.top
.Width = ctrl.width
.Height = ctrl.height
.Fontsize = ctrl.font.size
End with
NEXT
End Sub
'Update Size and Position of Controls on Parent Form
SUB Refresh ()
DIM I AS INTEGER, CTRL AS Control
Dim widthfactor as single, HeightFactor As Single
DIM minfactor as sales
'Inhibits Recursive Calls if Keepratio = TRUE
Static Executing as Boolean
If Executing Then EXIT SUB
If Ambient.usermode = false kil
If Keepratio Then
Executing = TRUE
'WE Must Keep Original Ratio
Parentform.height = heightwidthratio * _
Parentform.width
EXECUTING = FALSE
END IF
'this is Necessary for Controls That Don't Support' All Properties (E.G. Timer Controls)
ON Error ResMe next
Widthfactor = parentform.scalewidth / parentwidth
HeightFactor = ParentForm.scaleHeight / Parentheight
'Take the lesser of the two
If widthfactor Minfactor = Widthfactor Else Minfactor = HeightFactor END IF 'this is a regular resize For i = 0 to Ubound (Controls) WITH Controls (i) 'the change of font must ocur * before * the 'Resizing to Account for Companion Scrollbar 'of listbox and other Similar Controls IF resizefont dam .ctrl.font.size = .fontsize * minfactor END IF 'Move and Resize The Controls - We can't USE A 'Move Method Because Some Controls Do Not NOT 'Support The Change of All The Four Properties '(Eg. Height with ComboBoxes) .ctrl.Left = .left * widthfactor .ctrl.top = .top * HeightFactor .ctrl.width = .width * widthfactor .ctrl.height = .height * HeightFactor End with NEXT End Sub