Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modify behaviour of popup menu 1

Status
Not open for further replies.

svanels

MIS
Aug 18, 1999
1,393
SR
I have a button with a TpopupMenu tied to it, so a right-click on the button displays the popup menu.

I need to link the popup menu to the onclick event of the button (left click), how do I proceed?

Thanks in advance.

Steven
 
Just Double-click the in the Events tab of the Object Inspector of the button, next to "OnMouseUp". It will generate the following for you.
Code:
procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin

end;
Now, add the following so it looks like this:
Code:
procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if button = mbRight then
    PopupMenu1.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);
end;
The menu will pop-up wherever your mouse is. You could hard code it to pop-up at [100, 100] like this:
Code:
  PopupMenu1.Popup(100, 100);


Roo
Delphi Rules!
 
Thanks Roo, I did hard code it, but did not like the position,

I used:

Code:
if button = mbleft then

in your code snippet

Thanks!!


Steven
 
This method is required for mbRight. If using mbLeft, you can just use event "OnClick" which is the default (left button click). Thanks for the *star*!

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top