[453] | 1 | //kt -- Modified with SourceScanner on 7/12/2007
|
---|
| 2 | unit fAResize;
|
---|
| 3 |
|
---|
| 4 | interface
|
---|
| 5 |
|
---|
| 6 | uses
|
---|
| 7 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
|
---|
| 8 | fPage, ExtCtrls;
|
---|
| 9 |
|
---|
| 10 | type
|
---|
| 11 | TfrmAutoResize = class(TfrmPage)
|
---|
| 12 | procedure FormDestroy(Sender: TObject);
|
---|
| 13 | procedure FormResize(Sender: TObject);
|
---|
| 14 | private
|
---|
| 15 | FSizes: TList;
|
---|
| 16 | protected
|
---|
| 17 | procedure Loaded; override;
|
---|
| 18 | end;
|
---|
| 19 |
|
---|
| 20 | var
|
---|
| 21 | frmAutoResize: TfrmAutoResize;
|
---|
| 22 |
|
---|
| 23 | implementation
|
---|
| 24 |
|
---|
| 25 | {$R *.DFM}
|
---|
| 26 |
|
---|
| 27 | type
|
---|
| 28 | TSizeRatio = class // records relative sizes and positions for resizing logic
|
---|
| 29 | CLeft: Extended;
|
---|
| 30 | CTop: Extended;
|
---|
| 31 | CWidth: Extended;
|
---|
| 32 | CHeight: Extended;
|
---|
| 33 | constructor Create(ALeft, ATop, AWidth, AHeight: Extended);
|
---|
| 34 | end;
|
---|
| 35 |
|
---|
| 36 | { TSizeRatio methods }
|
---|
| 37 |
|
---|
| 38 | constructor TSizeRatio.Create(ALeft, ATop, AWidth, AHeight: Extended);
|
---|
| 39 | begin
|
---|
| 40 | CLeft := ALeft; CTop := ATop; CWidth := AWidth; CHeight := AHeight;
|
---|
| 41 | end;
|
---|
| 42 |
|
---|
| 43 | { TfrmAutoResize methods }
|
---|
| 44 |
|
---|
| 45 | procedure TfrmAutoResize.Loaded;
|
---|
| 46 | { record initial size & position info for resizing logic }
|
---|
| 47 | var
|
---|
| 48 | SizeRatio: TSizeRatio;
|
---|
| 49 | i,H,W: Integer;
|
---|
| 50 | begin
|
---|
| 51 | FSizes := TList.Create;
|
---|
| 52 | H := ClientHeight;
|
---|
| 53 | W := ClientWidth;
|
---|
| 54 | for i := 0 to ControlCount - 1 do with Controls[i] do
|
---|
| 55 | begin
|
---|
| 56 | SizeRatio := TSizeRatio.Create(Left/W, Top/H, Width/W, Height/H);
|
---|
| 57 | FSizes.Add(SizeRatio);
|
---|
| 58 | end;
|
---|
| 59 | inherited Loaded;
|
---|
| 60 | end;
|
---|
| 61 |
|
---|
| 62 | procedure TfrmAutoResize.FormResize(Sender: TObject);
|
---|
| 63 | { resize child controls using their design time proportions }
|
---|
| 64 | var
|
---|
| 65 | SizeRatio: TSizeRatio;
|
---|
| 66 | i,H,W: Integer;
|
---|
| 67 | begin
|
---|
| 68 | inherited;
|
---|
| 69 | H := Height;
|
---|
| 70 | W := Width;
|
---|
| 71 | with FSizes do for i := 0 to ControlCount - 1 do
|
---|
| 72 | begin
|
---|
| 73 | SizeRatio := Items[i];
|
---|
| 74 | with SizeRatio do
|
---|
| 75 | if Controls[i] is TLabel then with Controls[i] do
|
---|
| 76 | SetBounds(Round(CLeft*W), Round(CTop*H), Width, Height)
|
---|
| 77 | else
|
---|
| 78 | Controls[i].SetBounds(Round(CLeft*W), Round(CTop*H), Round(CWidth*W), Round(CHeight*H));
|
---|
| 79 | end; {with FSizes}
|
---|
| 80 | end;
|
---|
| 81 |
|
---|
| 82 | procedure TfrmAutoResize.FormDestroy(Sender: TObject);
|
---|
| 83 | { destroy objects used to record size and position information for controls }
|
---|
| 84 | var
|
---|
| 85 | SizeRatio: TSizeRatio;
|
---|
| 86 | i: Integer;
|
---|
| 87 | begin
|
---|
| 88 | inherited;
|
---|
| 89 | with FSizes do for i := 0 to Count-1 do
|
---|
| 90 | begin
|
---|
| 91 | SizeRatio := Items[i];
|
---|
| 92 | SizeRatio.Free;
|
---|
| 93 | end;
|
---|
| 94 | FSizes.Free;
|
---|
| 95 | end;
|
---|
| 96 |
|
---|
| 97 | end.
|
---|