Board index » delphi » Resizing Forms to fit Monitor

Resizing Forms to fit Monitor

Hello
I am relatively new to Delphi and am not sure where to post this question
having.

The problem is the application appears to look different on everybodies
monitors.  The only thing I've been able to deduce is the monitor
resolutions are different.  So I downloaded TSizer component but it did not
satisfy the problem.
I have a Delphi 5.0 application with several forms on them running on
Windows NT/95/98 and soon Windows 2000 platforms.  Some users use a
resolution of '640x480' pixels some use '800x600' pixels and yet others use
'1024x768' pixels.

Is there a programable method to obtain the clients PC resolution and modify
it during the running of the Delphi application?  Then reset the clients
resolution back to what it was prior to executing the application?

Thanks for any suggestions.

Ron

 

Re:Resizing Forms to fit Monitor


I run my display at 1600 x 1200. If I view a form that is 800 x 600 in
size it should file one quarter of the screen on my display. If I run
the same form on a machine with its display resolution set to 800 x
600 the form shoudl fill the screen. This is exactly what should
happen.

I gather that what you want to do is either change the user's screen
resolution or change the size of the form and the size and position of
everything on it.

I have no idea how to change the display resolution. You might try
asking in the winapi newsgroup, but I suspect most users would object
to this.

The best tool I have seen for dynamically resizing forms is GTSizer
from GenoTechs.

Quote
On Mon, 3 Jun 2002 08:23:42 -0500, "Ron" <ron_sp...@mhhs.org> wrote:
>Hello
>I am relatively new to Delphi and am not sure where to post this question
>having.

>The problem is the application appears to look different on everybodies
>monitors.  The only thing I've been able to deduce is the monitor
>resolutions are different.  So I downloaded TSizer component but it did not
>satisfy the problem.
>I have a Delphi 5.0 application with several forms on them running on
>Windows NT/95/98 and soon Windows 2000 platforms.  Some users use a
>resolution of '640x480' pixels some use '800x600' pixels and yet others use
>'1024x768' pixels.

>Is there a programable method to obtain the clients PC resolution and modify
>it during the running of the Delphi application?  Then reset the clients
>resolution back to what it was prior to executing the application?

>Thanks for any suggestions.

>Ron

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

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;

Re:Resizing Forms to fit Monitor


Hi Ron

please see the Delphi Pool at  http://www.lmc-mediaagentur.de/dpool.htm

Under Delphi -> Tips & Tricks -> User Interface -> Screen Design -> 0001 and
0002 and User Interface -> TForm you will find quite a few code snippets
that might help you.

Cheers
Uwe

Quote
> Is there a programable method to obtain the clients PC resolution and
modify
> it during the running of the Delphi application?  Then reset the clients
> resolution back to what it was prior to executing the application?

Other Threads