Link to home
Start Free TrialLog in
Avatar of ChLa
ChLaFlag for United States of America

asked on

Can I make a popup menu appear with a left click ?

Hi,
I put a popup menu on a panel and of course it pops up when I right-click the panel..
Can I also make it pop up for a left click ?
ASKER CERTIFIED SOLUTION
Avatar of jimyX
jimyX

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You have to use OnMouseDown and check for mbLeft (Left mouse button)

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then
    TPanel(Sender).PopupMenu.Popup(TPanel(Sender).ClientOrigin.X+X, TPanel(Sender).ClientOrigin.Y+Y);
end;

Just to be safe

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if (Button = mbLeft) and (Sender is TPanel) then
    TPanel(Sender).PopupMenu.Popup(TPanel(Sender).ClientOrigin.X+X, TPanel(Sender).ClientOrigin.Y+Y);
end;
ewangoya, reinventing the wheel this evening? :)

Of course Sender is Tpanel here. It's a Tpanel event!
I've typecasted it just to skip easy its name ;)

Hi,

Just set the TrackButton property of PopupMenu to *tbLeftButton*

bye

I can just as well do this
Panel1MouseDown(nil);
Avatar of ChLa

ASKER

I tried the first answer first because I thought I cuold use an on-click event, I didn't know the call to make the menu pop up. It worked perfectly.I appreciate everyone elses answer and learn from them also. The last two were especially interesting.
Avatar of ChLa

ASKER

Thank you