How do I set a form to show in the bottom right corner of the screen?

Freeday
Freeday used Ask the Experts™
on
Simple thing, I have a form that I want to always be positioned in the bottom right of the screen. Can I do this using the object inspector?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
You can't do this by using object inspector, but you can add FormCreate handler like this:

function SysTray_GetRect: TRect;
var
  H1, H2 : HWND;
begin
  Result:= Rect(0,0,0,0);
  H1 := FindWindow('Shell_TrayWnd', nil);
  if H1 <> 0 then
  begin
    H2 := FindWindowEx(H1, 0, 'TrayNotifyWnd', nil);
    if H2 <> 0 then
      GetWindowRect(H2, Result);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  SysTrayRect: TRect;
begin
  SysTrayRect:= SysTray_GetRect;
  Top:= SysTrayRect.Top - Height;
  Left:= SysTrayRect.Right - Width;
end;
Geert GOracle dba
Top Expert 2009

Commented:
it's a shame the property Align doesn't have alBottomRight

otherwise setting that and ScreenSnap would have done it
Now it only gives either Left or Bottom, not both

unless ... set Align to alCustom
and set ScreenSnap = True

and add this to the formCreate
procedure TfrmAlterMemo.FormCreate(Sender: TObject);
begin
  Left := Screen.WorkAreaWidth - Width;
  Top := Screen.WorkAreaHeight - Height;
end;

That will hold the form in that position, immovable !

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial