Name | Modified | Size | Downloads / Week |
---|---|---|---|
Parent folder | |||
ReadMe.md | 2024-04-12 | 3.1 kB | |
Rcs_Resize.pas | 2024-02-16 | 11.6 kB | |
Totals: 2 Items | 14.7 kB | 0 |
RCS_Resize
The purpose of this unit is to reszize all components on a form when the form itself is resized.
Usage
The usage is very simple: this is the interface between the using program and the unit:
On every form that needs its components resize add the following:
- Create a variable of the type 'TMyResize':
var MyResize_: TMyResize;
- Add in the 'Form.Create' event:
MyResize_ := TMyResize.Create(Self);
- Add in the 'Form.Resize' event:
MyResize_.Resize(Self);
- Add in the 'Form.destroy' event:
MyResize_.Free;
The "standard behaviour" is:
The resize unit calculates from the old and the new form Width en hight the horizontal and vertical zoom factors and adapts for all components on the form the height, the width, the left and the top values trough simple multiplication. The resizing is recursive, e.g. a Panel on the form gets resized and also all components on that panel become resized (and repositioned).
Deviations of standard behaviour
For components that need a deviation on the resizing method there is a callback routine available. This routine is called for every component when it is to become resized.
The signature of this routine is:
type TResizeCallbackFunction = function(Control: TControl; VFactor, HFactor: real; L, W, H, T
{$IFDEF FONTRESIZE}
, S
{$ENDIF}
: integer): boolean;
The routine parameters: Control: the component about to resize; VFactor en HFactor: the zoom factors; L, W, H, T: the original positions and dimensions of the component; S: the original fontsize of the item.
This routine has to return a boolean: false: means the callback routine did NO resizing (this means the standard resizing behaviour will be used); true: means the callback routine DID the resizing (and the standard behaviour is switched off).
The routine itself looks like this (example):
function ResizeCallbackFunction(Control: TControl; VFactor, HFactor: real; L, W, H, T
{$IFDEF FONTRESIZE}
, S
{$ENDIF}
: integer): boolean;
var Tsg: TStringGrid;
begin
Result := false; // resizing not handled here = default
if Control.Name = 'StringGrid3' then // special case
begin
Result := true; // resizing handled here
// calculate new values
W := Trunc(HFactor * W);
H := Trunc(VFactor * H);
L := Trunc(HFactor * L);
T := Trunc(VFactor * T);
// and use them
Tsg := Control as TStringGrid;
Tsg.Left := L;
Tsg.Top := T;
Tsg.DefaultColWidth := W + 20; // to be sure column 1 is always invisible
Tsg.DefaultRowHeight := (H div Tsg.RowCount);
Tsg.Width := W;
Tsg.Height := H;
end;
end;
The callback routine (if any) is activated in the 'Create' call:
MyResize_ := TMyResize.Create(Self, ResizeCallbackFunction);
Compiler directives
The unit uses 2 compilerdirectives: FONTRESIZE: the font of the components is also adapted to the calculated zoomfactors STRINGGRIDRESIZE: Also Stringgrids are resized. The standard behaviour is all rows the same size.
Have fun!