FMXTPopupMenu (Delphi)
Contents
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 - Delphi > Blank Application, and add the following objects on the form:
- A TButton component.
- A TPopupMenu component, preferably with at least one menu item.
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
- FMX.StdCtrls.TButton ( fr | de | ja )
- FMX.Menus.TPopupMenu ( fr | de | ja )
- FMX.Forms.TCommonCustomForm.ClientToScreen ( fr | de | ja )
- FMX.Menus.TPopupMenu.Popup ( fr | de | ja )