unit Formtools;
interface;
uses
Windows
, Forms
, Grids
;
const Zeilenhoehe=17;Zellenbreitenzuschlag=6;
procedure Form_Skalieren(Form:TForm;StringGrid:TStringGrid);
implementation;
procedure Form_Skalieren(Form:TForm;StringGrid:TStringGrid);
var l,m:word;
begin
Form.Hide;
//Spaltenbreitenskalierung des Grids
for l:=0
to pred(StringGrid.ColCount)
do StringGrid.ColWidths[l]:=Zellenbreitenzuschlag+StringGrid.Canvas.TextWidth(StringGrid.Cells[l,0]);
//Skalieren nach Tabellenkopf
for l:=0
to pred(StringGrid.ColCount)
do for m:=1
to pred(StringGrid.RowCount)
do
if StringGrid.ColWidths[l]<Zellenbreitenzuschlag+StringGrid.Canvas.TextWidth(StringGrid.Cells[l,m])
then StringGrid.ColWidths[l]:=Zellenbreitenzuschlag+StringGrid.Canvas.TextWidth(StringGrid.Cells[l,m]);
//maximale horizontale Ausdehnung des Fensters ermitteln
Form.Width:=1;
while ((GetWindowlong(StringGrid.Handle,GWL_STYLE)
and WS_HSCROLL)<>0)
and (Form.width<screen.width)
do Form.Width:=succ(Form.Width);
//maximale vertikale Ausdehnung des Fensters ermitteln
Form.Height:=succ(Form.Height-Form.ClientHeight);
while ((GetWindowlong(StringGrid.Handle,GWL_STYLE)
and WS_VSCROLL)<>0)
and (Form.Height<Screen.Height)
do Form.Height:=succ(Form.Height);
//Horizontalkorrektur; es ginge wohl auch umgekehrt: 1. vertikale, 2. horizontale Ausdehnung ermitteln und schließlich Vertikalkorrektur
if ((GetWindowlong(StringGrid.Handle,GWL_STYLE)
and WS_HSCROLL)=0)
then //Horizontalscrollleiste nicht zu sehen
begin
while (GetWindowlong(StringGrid.Handle,GWL_STYLE)
and WS_HSCROLL)=0
do Form.Width:=pred(Form.Width);
Form.Width:=succ(Form.Width)
end;
Form.Position:=poScreenCenter;
Form.Show
end;
end.