FMXTPopupMenu (Object Pascal)

From Appmethod Code Examples
Jump to: navigation, search

Description

This example shows how to display a TPopupMenu component in the upper left corner of a TButton component, when left-clicking the button.

To test this example, create a Multi-Device Application - Object Pascal > Blank Application, and add the following objects on the form:


Add the following code for the OnClick event of the TButton component.

Code

procedure TForm1.Button1Click(Sender: TObject);
var
  FP: TPointF;
begin
  //Initialize the coordinates to the origin of the button control.
  FP.X := 0;
  FP.Y := 0;
  //Transposes the coordinates in the context of the form.
  FP := Button1.LocalToAbsolute(FP);
  //Transposes the coordinates in the context of the screen.
  FP := ClientToScreen(FP);
  //Display the popup menu at the computed coordinates.
  PopupMenu1.Popup(FP.X, FP.Y);
end;

Uses

See Also