Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

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 ?
0
ChLa
Asked:
ChLa
  • 2
  • 2
  • 2
  • +2
1 Solution
 
jimyXCommented:
Left click means OnClick:
procedure TForm1.Panel1Click(Sender: TObject);
begin
  PopupMenu1.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);
end;

Open in new window

0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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;
0
 
Ephraim WangoyaCommented:

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;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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 ;)

0
 
paulo_psaCommented:
Hi,

Just set the TrackButton property of PopupMenu to *tbLeftButton*

bye
0
 
Ephraim WangoyaCommented:

I can just as well do this
Panel1MouseDown(nil);
0
 
ChLaAuthor Commented:
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.
0
 
ChLaAuthor Commented:
Thank you
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now