Default
Google

How can I show a PopupMenu under the mouse cursor?

Applies To: C++Builder 1 or higher
Category: Knowledge Base

 
 1.
  Start a new project using File | New Application.
 
 2.
  Add a PopupMenu. Insert some sample items.
 
 3.
  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



Acquiring image from ProHosting Banner Exchange