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