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