source: cprs/branches/foia-cprs/CPRS-Chart/fAResize.pas@ 1381

Last change on this file since 1381 was 459, checked in by Kevin Toppenberg, 16 years ago

Adding foia-cprs branch

File size: 2.2 KB
Line 
1unit fAResize;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
7 fPage, ExtCtrls;
8
9type
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
19var
20 frmAutoResize: TfrmAutoResize;
21
22implementation
23
24{$R *.DFM}
25
26type
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
37constructor TSizeRatio.Create(ALeft, ATop, AWidth, AHeight: Extended);
38begin
39 CLeft := ALeft; CTop := ATop; CWidth := AWidth; CHeight := AHeight;
40end;
41
42{ TfrmAutoResize methods }
43
44procedure TfrmAutoResize.Loaded;
45{ record initial size & position info for resizing logic }
46var
47 SizeRatio: TSizeRatio;
48 i,H,W: Integer;
49begin
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;
59end;
60
61procedure TfrmAutoResize.FormResize(Sender: TObject);
62{ resize child controls using their design time proportions }
63var
64 SizeRatio: TSizeRatio;
65 i,H,W: Integer;
66begin
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}
79end;
80
81procedure TfrmAutoResize.FormDestroy(Sender: TObject);
82{ destroy objects used to record size and position information for controls }
83var
84 SizeRatio: TSizeRatio;
85 i: Integer;
86begin
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;
94end;
95
96end.
Note: See TracBrowser for help on using the repository browser.