Unlike VCL forms, Delphi FireMonkey forms do not have a PopupMenu property. So how can you show a popup menu when the user clicks the Right Mouse Button ?
You have to code it yourself and its pretty easy to do. The tricky bit is converting the X/Y position from the forms local co-ordinate system to global co-ordinates. Ill show you to do that.
Instructions
- Create a popup menu on the form
Add menu items to it in the usual way.
I presume you know how to do.
2. Create an OnMouseDown event for the form with this code
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single); var vPoint : TPointF; begin // show popup menu when right mouse button if Button = TMouseButton.mbRight then begin -- convert local XY to global XY vPoint := Self.ClientToScreen(PointF (X,Y)); PopupMenu1.Popup(vPoint.X, vPoint.Y); end; end;
3. Run the project (F9 Key)
4. Right click on the form.
The popup menu should appear at the mouse location
Convert local co-ordinates to global co-ordinates
Popup menus can be displayed anywhere on the screen, even outside of the form’s display area. As a result, the X/Y position for the popup menu is defined using global coordinates instead of the Forms local co-ordinates.
The above code converts the X and Y arguments from local co-ordinate to global co-ordinates like this:
vPoint := Self.ClientToScreen(PointF (X,Y));
+1 this post
If you like this post, please +1 vote here to get it listed on Delphi Feeds and also here on BeginEnd. Thank You
About Me
- Oracle & Delphi software developer based in Perth, Western Australia
- Australian Delphi User Group – WA Chief Cat Herder
- Australian Delphi User Group – President
![]() |
![]() |
![]() |
Leave a Reply