Board index » delphi » Align a form on the screen with the Align property

Align a form on the screen with the Align property

I have a simple problem: I would like to align two forms on the screen,
one in the top, left corner and one in the right, bottom corner of the
desktop. The first is easy: TForm.Top := 0 and TForm.Left := 0, for the
second I calculated Top and Left using Width, Height and Screen.Width
and Screen.Height. Is there an easier way to do it? If I use TForm.Align
:= alBottom the form's width is changed to full screen width.

Thanks in advance for your help.

Best regards,

Rolf

--
----------------------------------------------------------------
Rolf Fankhauser, PhD
ETHZ - Federal Institute of Technology Zurich
Institute of Hydromechanics and Water Resources Management
Urban Water Management Division
G 31.3
CH-8093 Zuerich-Hoenggerberg
Switzerland
Tel. +41-1-633 25 07
Fax. +41-1-633 10 61

 

Re:Align a form on the screen with the Align property


Rolf Fankhauser <fankhau...@eawag.ch> skrev i en
nyhedsmeddelelse:38749FE8.B8EF4...@eawag.ch...

Quote
> I have a simple problem: I would like to align two forms on the screen,
> one in the top, left corner and one in the right, bottom corner of the
> desktop. The first is easy: TForm.Top := 0 and TForm.Left := 0, for the

Sorry, this is not good enough.
Some people might have the taskbar placed on the top or on the sides of the
screen, and then your code will not be so good.

Quote
> second I calculated Top and Left using Width, Height and Screen.Width
> and Screen.Height. Is there an easier way to do it? If I use TForm.Align
> := alBottom the form's width is changed to full screen width.

Just do it this way:

procedure TForm1.PutFormAtTopLeft;
var
  arect: TRect;
begin
  SystemParametersInfo(SPI_GETWORKAREA, 0, @arect, 0);
  Left := arect.Left;
  Top := arect.Top;
end;

procedure TForm1.PutFormAtBottomRight;
var
  arect: TRect;
begin
  SystemParametersInfo(SPI_GETWORKAREA, 0, @arect, 0);
  Left := arect.Right - Width;
  Top := arect.Bottom - Height;
end;

Finn Tolderlund

Re:Align a form on the screen with the Align property


Thanks a lot for the hint. I already thought how to determine the size of the
working area. But the compiler doesn't know SystemParametersInfo. In which unit
is it defined? I think it is a Windows API procedure?

Rolf Fankhauser

Quote
Finn Tolderlund wrote:
> Rolf Fankhauser <fankhau...@eawag.ch> skrev i en
> nyhedsmeddelelse:38749FE8.B8EF4...@eawag.ch...
> > I have a simple problem: I would like to align two forms on the screen,
> > one in the top, left corner and one in the right, bottom corner of the
> > desktop. The first is easy: TForm.Top := 0 and TForm.Left := 0, for the

> Sorry, this is not good enough.
> Some people might have the taskbar placed on the top or on the sides of the
> screen, and then your code will not be so good.

> > second I calculated Top and Left using Width, Height and Screen.Width
> > and Screen.Height. Is there an easier way to do it? If I use TForm.Align
> > := alBottom the form's width is changed to full screen width.

> Just do it this way:

> procedure TForm1.PutFormAtTopLeft;
> var
>   arect: TRect;
> begin
>   SystemParametersInfo(SPI_GETWORKAREA, 0, @arect, 0);
>   Left := arect.Left;
>   Top := arect.Top;
> end;

> procedure TForm1.PutFormAtBottomRight;
> var
>   arect: TRect;
> begin
>   SystemParametersInfo(SPI_GETWORKAREA, 0, @arect, 0);
>   Left := arect.Right - Width;
>   Top := arect.Bottom - Height;
> end;

> Finn Tolderlund

--
----------------------------------------------------------------
Rolf Fankhauser, PhD
ETHZ - Federal Institute of Technology Zurich
Institute of Hydromechanics and Water Resources Management
Urban Water Management Division
G 31.3
CH-8093 Zuerich-Hoenggerberg
Switzerland
Tel. +41-1-633 25 07
Fax. +41-1-633 10 61

Re:Align a form on the screen with the Align property


Ok, I found the error. Unit Windows was not included in my unit where I put the
align function for forms.

Rolf Fankhauser

Quote
Finn Tolderlund wrote:
> Rolf Fankhauser <fankhau...@eawag.ch> skrev i en
> nyhedsmeddelelse:38749FE8.B8EF4...@eawag.ch...
> > I have a simple problem: I would like to align two forms on the screen,
> > one in the top, left corner and one in the right, bottom corner of the
> > desktop. The first is easy: TForm.Top := 0 and TForm.Left := 0, for the

> Sorry, this is not good enough.
> Some people might have the taskbar placed on the top or on the sides of the
> screen, and then your code will not be so good.

> > second I calculated Top and Left using Width, Height and Screen.Width
> > and Screen.Height. Is there an easier way to do it? If I use TForm.Align
> > := alBottom the form's width is changed to full screen width.

> Just do it this way:

> procedure TForm1.PutFormAtTopLeft;
> var
>   arect: TRect;
> begin
>   SystemParametersInfo(SPI_GETWORKAREA, 0, @arect, 0);
>   Left := arect.Left;
>   Top := arect.Top;
> end;

> procedure TForm1.PutFormAtBottomRight;
> var
>   arect: TRect;
> begin
>   SystemParametersInfo(SPI_GETWORKAREA, 0, @arect, 0);
>   Left := arect.Right - Width;
>   Top := arect.Bottom - Height;
> end;

> Finn Tolderlund

--
----------------------------------------------------------------
Rolf Fankhauser, PhD
ETHZ - Federal Institute of Technology Zurich
Institute of Hydromechanics and Water Resources Management
Urban Water Management Division
G 31.3
CH-8093 Zuerich-Hoenggerberg
Switzerland
Tel. +41-1-633 25 07
Fax. +41-1-633 10 61

Re:Align a form on the screen with the Align property


Quote
In article <3875AAAC.A859A...@eawag.ch>, Rolf Fankhauser wrote:
> But the compiler doesn't know SystemParametersInfo. In which unit
> is it defined?

Windows. That is part of the standard Uses list of a form unit,
unless you removed it yourself.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Sent using Virtual Access 5.00 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Other Threads