user2972081
user2972081

Reputation: 671

Show a form on bottom right position of the screen

I noticed a strange issue in a Delphi 11.1 Windows application.

I need to show Form3 on the lower right of the screen after 5 minutes a button is clicked:

procedure TForm1.Timer2Timer(Sender: TObject);
begin
  Timer2.Enabled := False;
        
  // Set form position on bottom right of the screen
  with Form3 do
  begin
  Top := Screen.Height - Form3.Height - GetTaskBar_Y_Bottom_Height();
  Left := Screen.Width - Form3.Width - GetTaskBar_X_Right_Width();
  end;
 
  // Now show the form
  Form3.Show;
end;
    
procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer2.Enabled := True;
end;

It works fine and the Form3 is shown on the lower right of the screen... well, most of the time.

Because on some occasions, it is shown on the top left of the screen:

enter image description here

Even if Screen.Height and Screen.Width are correct:

Screen.Height = 1080
Screen.Width = 1920

Do you have any suggestion what can be?

Some additional details:

Upvotes: 1

Views: 762

Answers (1)

Tom Brunberg
Tom Brunberg

Reputation: 21045

As you did not yet respond to my request for the GetTaskBar... functions, we can just ditch them and use a better method to assess the available work area.

Also, you do not account for the position of the taskbar. Many, if not most, users let it stay on the bottom, but users may prefer to keep it at left, at top or at right edge of the monitor.

To account for the different layouts, you can use something like this OnShow event of Form3:

procedure TForm3.FormShow(Sender: TObject);
begin
  Left := Screen.WorkAreaRect.Right - Width;
  Top := Screen.WorkAreaRect.Bottom - Height;
end;

And you would call it from the timer event in Form1

procedure TForm1.Timer2Timer(Sender: TObject);
begin
  Timer2.Enabled := False;
  Form3.Show;
end;

Upvotes: 3

Related Questions