source: cprs/trunk/CPRS-Chart/fAutoSz.pas@ 776

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

Initial Upload of Official WV CPRS 1.0.26.76

File size: 3.2 KB
Line 
1unit fAutoSz;
2{ provides the basic mechanism to resize all the controls on a form when the form size is
3 changed. Differs from frmAResize in that this one descends directly from TForm, rather
4 than TPage }
5
6interface
7
8uses
9 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
10
11type
12 TfrmAutoSz = class(TForm)
13 procedure FormResize(Sender: TObject);
14 procedure FormDestroy(Sender: TObject);
15 private
16 FSizes: TList;
17 FAutoSizeDisabled: Boolean;
18 protected
19 property AutoSizeDisabled: Boolean read FAutoSizeDisabled write FAutoSizeDisabled;
20 public
21 procedure Loaded; override;
22 end;
23
24var
25 frmAutoSz: TfrmAutoSz;
26
27implementation
28
29{$R *.DFM}
30
31uses
32 ORfn;
33type
34 TSizeRatio = class // records relative sizes and positions for resizing logic
35 FControl: TControl;
36 FLeft: Extended;
37 FTop: Extended;
38 FWidth: Extended;
39 FHeight: Extended;
40 constructor Create(AControl: TControl; W, H: Integer);
41 end;
42
43{ TSizeRatio methods }
44
45constructor TSizeRatio.Create(AControl: TControl; W, H: Integer);
46begin
47 FControl := AControl;
48 with AControl do
49 begin
50 FLeft := Left / W;
51 FTop := Top / H;
52 FWidth := Width / W;
53 FHeight := Height / H;
54 end;
55end;
56
57{ TfrmAutoSz methods }
58
59procedure TfrmAutoSz.Loaded;
60{ record initial size & position info for resizing logic }
61var
62 SizeRatio: TSizeRatio;
63 i,W,H: Integer;
64 Control: TControl;
65begin
66 inherited Loaded;
67 FSizes := TList.Create;
68 if AutoSizeDisabled then Exit;
69 W := ClientWidth;
70 H := ClientHeight;
71 for i := 0 to ComponentCount - 1 do if Components[i] is TControl then
72 begin
73 Control := TControl(Components[i]);
74 W := HigherOf(W, Control.Left + Control.Width);
75 H := HigherOf(H, Control.Top + Control.Height);
76 end;
77 ClientHeight := H;
78 ClientWidth := W;
79 for i := 0 to ComponentCount - 1 do if Components[i] is TControl then
80 begin
81 SizeRatio := TSizeRatio.Create(TControl(Components[i]), W, H);
82 FSizes.Add(SizeRatio);
83 end;
84end;
85
86procedure TfrmAutoSz.FormResize(Sender: TObject);
87{ resize child controls using their design time proportions }
88var
89 SizeRatio: TSizeRatio;
90 i, W, H: Integer;
91begin
92 inherited;
93 if AutoSizeDisabled then Exit;
94 W := HigherOf(ClientWidth, HorzScrollBar.Range);
95 H := HigherOf(ClientHeight, VertScrollBar.Range);
96 with FSizes do for i := 0 to Count - 1 do
97 begin
98 SizeRatio := Items[i];
99 with SizeRatio do
100 if ((FControl is TLabel) and TLabel(FControl).AutoSize) or ((FControl is TStaticText) and TStaticText(FControl).AutoSize) then
101 begin
102 FControl.Left := Round(FLeft*W);
103 FControl.Top := Round(FTop*H);
104 end
105 else FControl.SetBounds(Round(FLeft*W), Round(FTop*H), Round(FWidth*W), Round(FHeight*H));
106 end; {with FSizes}
107end;
108
109procedure TfrmAutoSz.FormDestroy(Sender: TObject);
110{ destroy objects used to record size and position information for controls }
111var
112 SizeRatio: TSizeRatio;
113 i: Integer;
114begin
115 inherited;
116 if FSizes <> nil then with FSizes do for i := 0 to Count-1 do
117 begin
118 SizeRatio := Items[i];
119 SizeRatio.Free;
120 end;
121 FSizes.Free;
122end;
123
124end.
Note: See TracBrowser for help on using the repository browser.