Forum > Packages and Libraries

Use codes to add submenus of PopupMenu

(1/1)

asdf:
I need to use 'options' in a dialog box like InputBox. Is it possible? ( I don't need to create a new form for it.)

Or if I apply by using PopupMenu, how can I write codes to add a new submenu?
And how can I use double click instead of right click on the control?

Blaazen:
Hi,

--- Quote ---I need to use 'options' in a dialog box like InputBox. Is it possible? ( I don't need to create a new form for it.)
--- End quote ---
I don't understand well.


--- Quote ---Or if I apply by using PopupMenu, how can I write codes to add a new submenu?
--- End quote ---

--- Code: ---var MI: TMenuItem;
begin
  MI:=TMenuItem.Create(self);
  with MI do
    begin
      Caption:='My New Item '+inttostr(PopupMenu1.Items.Count);
      //also do not forget to assign some action or event
    end;
  PopupMenu1.Items.Add(MI); 
end;

--- End code ---

--- Quote ---And how can I use double click instead of right click on the control?
--- End quote ---
Let's say you have Image1 and Image1Click event. In code you can switch:

--- Code: ---      Image1.OnClick:=nil;
      Image1.OnDblClick:=@Image1Click;

--- End code ---
or

--- Code: ---      Image1.OnClick:=@Image1Click;
      Image1.OnDblClick:=nil;

--- End code ---

User137:
Rather than adding new menus (which you can do with TMenuItem.Create), you can change their visibility. Give your menuitems some relevant names like mnuOptions, and then use
mnuOptions.Visible:=true;
or
mnuToggle1.Caption:='Something';

Navigation

[0] Message Index

Go to full version