Adding a right click menu to an item

Marshal picture Marshal · Mar 22, 2012 · Viewed 146.8k times · Source

I have been searching for a while for a simple right-click menu for a single item. For example if I right-click on a picture I want a little menu to come up with my own labels: Add, Remove etc. If anyone could help I would be most greatful.

Thanks for looking.

Here is the completed code:

    ContextMenu cm = new ContextMenu();             
    cm.MenuItems.Add("Item 1", new EventHandler(Removepicture_Click));             
    cm.MenuItems.Add("Item 2", new EventHandler(Addpicture_Click));              
    pictureBox1.ContextMenu = cm; 

Answer

Yuki Kutsuya picture Yuki Kutsuya · Mar 22, 2012

Add a contextmenu to your form and then assign it in the control's properties under ContextMenuStrip. Hope this helps :).

Hope this helps:

ContextMenu cm = new ContextMenu();
cm.MenuItems.Add("Item 1");
cm.MenuItems.Add("Item 2");

pictureBox1.ContextMenu = cm;