Re: Delphi popupmenu to remain expanded


[ Delphi Forum ]

Posted by webmaster Guido on January 31, 2004

In Reply to: get Delphi popupmenu to remain expanded posted by Stefan Loeners on January 28, 2004

: Is there any way I can make a popupmenu NOT close automatically after selecting a menu item?
: In other words, how can I keep in an "opened" state.
: Thank you for your help.
----------------------------------

Disabling the automatic closing of a popupmenu is impossible... but you can re-open it after a selection was made. A source code example:

procedure TForm1.Item1Click(Sender: TObject);
begin
  ShowMessage('Item 1 was clicked'); 
  PopupMenu1.Popup(Left + 50, Top + 100);
end;

In the example above, Left and Right refer to the coordinates of the form. That's for changing the popup-position when the form is moved.

So, simply add PopupMenu1.Popup(X, Y) at the end of every event-handler of the menu-items.

How to close the menu? If nothing is selected but the Escape key is pressed, the menu is closed automatically. You also might add an extra item with the caption "Close menu", without an event handler: this last one will automagically close the menu ;-)))


Related Articles and Replies:


[ Delphi Forum ]