Title: How to emulate the "Size" tool at run-time
Question: My last article was about emulating the "Align" tool in Delphi at runtime. Now it's time to emulate the "Size" tool.
Easy as the "Align" one!
Answer:
Procedure HeightLargerControls( ComponentsList : Array Of TControl );
Var
MaxH : Integer;
IdX : Integer;
Begin
If ( High( ComponentsList ) Low( ComponentsList ) ) Then Begin
MaxH := ComponentsList[ Low( ComponentsList ) ].Height;
For IdX := Low( ComponentsList ) To High( ComponentsList ) Do
If ( ComponentsList[ IdX ].Height MaxH ) Then
MaxH := ComponentsList[ IdX ].Height;
For IdX := Low( ComponentsList ) To High( ComponentsList ) Do
ComponentsList[ IdX ].Height := MaxH;
End;
End;
Procedure HeightSmallerControls( ComponentsList : Array Of TControl );
Var
MinH : Integer;
IdX : Integer;
Begin
If ( High( ComponentsList ) Low( ComponentsList ) ) Then Begin
MinH := ComponentsList[ Low( ComponentsList ) ].Height;
For IdX := Low( ComponentsList ) To High( ComponentsList ) Do
If ( ComponentsList[ IdX ].Height MinH := ComponentsList[ IdX ].Height;
For IdX := Low( ComponentsList ) To High( ComponentsList ) Do
ComponentsList[ IdX ].Height := MinH;
End;
End;
Procedure WidthLargerControls( ComponentsList : Array Of TControl );
Var
MaxW : Integer;
IdX : Integer;
Begin
If ( High( ComponentsList ) Low( ComponentsList ) ) Then Begin
MaxW := ComponentsList[ Low( ComponentsList ) ].Width;
For IdX := Low( ComponentsList ) To High( ComponentsList ) Do
If ( ComponentsList[ IdX ].Width MaxW ) Then
MaxW := ComponentsList[ IdX ].Width;
For IdX := Low( ComponentsList ) To High( ComponentsList ) Do
ComponentsList[ IdX ].Width := MaxW;
End;
End;
Procedure WidthSmallerControls( ComponentsList : Array Of TControl );
Var
MinW : Integer;
IdX : Integer;
Begin
If ( High( ComponentsList ) Low( ComponentsList ) ) Then Begin
MinW := ComponentsList[ Low( ComponentsList ) ].Width;
For IdX := Low( ComponentsList ) To High( ComponentsList ) Do
If ( ComponentsList[ IdX ].Width MinW := ComponentsList[ IdX ].Width;
For IdX := Low( ComponentsList ) To High( ComponentsList ) Do
ComponentsList[ IdX ].Width := MinW;
End;
End;
Procedure WidthConstantControls( NewWidth : Integer; ComponentsList : Array Of TControl );
Var
IdX : Integer;
Begin
If ( Low( ComponentsList ) -1 ) Then
For IdX := Low( ComponentsList ) To High( ComponentsList ) Do
ComponentsList[ IdX ].Width := NewWidth;
End;
Procedure HeightConstantControls( NewHeight : Integer; ComponentsList : Array Of TControl );
Var
IdX : Integer;
Begin
If ( Low( ComponentsList ) -1 ) Then
For IdX := Low( ComponentsList ) To High( ComponentsList ) Do
ComponentsList[ IdX ].Height := NewHeight;
End;
Use the first four like this:
WidthLargerControls( [ Button1, Button2, Button3 ] );
and the other two like this:
HeightConstantControls( 100, [ Button1, Button2, Button4 ] );