How can I show a PopupMenu under the mouse cursor?
Applies To: C++Builder 1 or higher
Category: Knowledge Base

-
- Start a new project using File | New Application.
-
- Add a PopupMenu. Insert some sample items.
-
- Double-click the OnMouseDown event of your form:
-
- void __fastcall TForm1::FormMouseDown(TObject *Sender,
- TMouseButton Button,TShiftState Shift, int X, int Y)
- {
- TPoint p = ClientToScreen(Point(X, Y));
- PopupMenu1->Popup(p.x, p.y);
- }
-
- The Popup method allows you to bring up the PopupMenu. The coordinates used by this method are screen-related and you have to use the ClientToScreen procedure.
C++Builder Developer's Network
Copyright © Yoto Yotov