Search code examples
delphipopupfiremonkey

Delphi 10.2.2 popup position


procedure TForm1.Button1Click(Sender: TObject);
begin
  Popup1.Position.X := (Self.Width + Popup1.Width) / 2;
  Popup1.Position.Y := (Self.Height + Popup1.Height) / 2;
  Popup1.Popup(False);
end;

I'm trying to center the popup on the mobile device. Even after setting the Position in code, the popup still appears wherever the user clicks on the button.

How do I get the popup to appear centered on the screen? Or wherever I want it to appear?


Solution

  • The documentation was confusing to me but it made it clear that setting the TPopup's position would do nothing.

    I ended up changing the TPopup's Placement to Center in the designer. Then in the form's FormResize() I added...

     Popup1.VerticalOffset := Self.Height / 2;
     Popup1.HorizontalOffset := Self.Width / 2;
    

    This works on mobile.