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

Last change on this file since 893 was 830, checked in by Kevin Toppenberg, 14 years ago

Upgrading to version 27

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