Re:Resizing Forms to fit Monitor
Quote
"Ron" <ron_sp...@mhhs.org> wrote in message
news:3cfb6dde$1_1@dnews...
Quote
> Hello
> Is there a programable method to obtain the clients PC
resolution and modify
Quote
> it during the running of the Delphi application? Then reset the
clients
> resolution back to what it was prior to executing the
application?
You really don't want to mess with the users settings this way. A
better method, IMO, is to adjust the form size and scaling based
on the resolution. Here is a method I use for all my forms. I give
the users a setting in their setup which lets them choose whether
or not they want their forms scaled. If they do, each one calls
this in their OnCreate method. The function will scale a form
based on a default size of 640x480. If the user is using a higher
resolution, the form (and everything on it) is scaled up to
produce a large image. It resizes columns in grid as well. The
return value is the percent of scaling, 100 percent being not
scaled at all. All you need to do is put this somewhere you can
call it from anywhere and in each form's OnCreate event, put a
call to it:
FixFormScale(self);
HTH
Woody
function FixFormScale(f: TForm): integer;
const
OrigSize = 640;
var
x,y: integer;
begin
f.AutoScroll := false;
if (Screen.Width <> OrigSize) then begin
result := Round(((Screen.Width-OrigSize)/OrigSize)*80)+100;
f.ScaleBy(result, 100);
for y := 0 to f.ComponentCount-1 do begin
if (f.Components[y] is TListView) and
(TListView(f.Components[y]).Columns.Count > 0) then
begin
for x := 0 to TListView(f.Components[y]).Columns.Count-1
do
TListView(f.Components[y]).Columns[x].Width :=
Trunc(TListView(f.Components[y]).Columns[x].Width
* (result / 100));
end;
if (f.Components[y] is TStringGrid) then begin
TStringGrid(f.Components[y]).DefaultColWidth :=
Trunc(TStringGrid(f.Components[y]).DefaultColWidth *
(result / 100));
TStringGrid(f.Components[y]).DefaultRowHeight :=
Trunc(TStringGrid(f.Components[y]).DefaultRowHeight
* (result / 100));
end;
if (f.Components[y] is TDBGrid) and
(TDBGrid(f.Components[y]).Columns.Count > 0) then
for x := 0 to TDBGrid(f.Components[y]).Columns.Count-1
do
TDBGrid(f.Components[y]).Columns[x].Width :=
Trunc(TDBGrid(f.Components[y]).Columns[x].Width
* (result / 100));
end;
end else
result := 100;
end;