source: cprs/branches/tmg-cprs/CPRS-Chart/fAutoSz.pas@ 1725

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

Initial upload of TMG-CPRS 1.0.26.69

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