Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello!

I have a ContextMenu with assorted items added.

How do I add icons onto these items?

I have googled, but the only available answers deal with ContextMenuStrips, and not ContextMenu's.

What I want to do:


ContextMenu trayMenu;
trayMenu.MenuItems.Add("Hello");
trayMenu.MenuItems[0].Icon = ....;


Unfortunately the ".Icon" property is non-existent.

See screenshots for clarification.

Mine looks like:

http://i52.tinypic.com/5oz586.png[^]

I want it to look like:

http://i52.tinypic.com/zx8u1y.png[^]

With those icons at the left.

Any help would be greatly appreciated!
Posted
Updated 29-Jun-11 15:59pm
v4

1 solution

Why not using ContextMenuStrip? There is nothing wrong with it.

You can use System.Windows.Forms.MenuStrip or System.Windows.Forms.<code>ContextMenuStrip. For these menus, you can use the instances of the class System.Windows.Forms.ToolStripMenuItem for items. It can be instantiated with individual image using constructors ToolStripMenuItem(String, Image), ToolStripMenuItem(String, Image, EventHandler) or ToolStripMenuItem(String, Image, ToolStripItem[]). Alternatively, this menu item can use property ImageKey or ImageIndex to select the image in the image list, which is set as a property MenuStrip or ContextMenuStrip; the property is inherited property System.Windows.Forms.ToolStrip.ImageList.
See:
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstrip.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.menustrip.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.contextmenustrip.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripitem.imageindex.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripitem.imagekey.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripitem.imageindex.aspx[^].

—SA
 
Share this answer
 
v4
Comments
Reelix 30-Jun-11 0:49am    
Decided to go with ContextMenuStrip, and found the links extremely helpful!

Thanks! :D
Sergey Alexandrovich Kryukov 30-Jun-11 2:57am    
Reasonable decision.
Well, thanks for accepting the solution.
Good luck,
--SA
[no name] 30-Jun-11 2:16am    
Good Call SA. My 5 too.
Sergey Alexandrovich Kryukov 30-Jun-11 2:57am    
Thank you, Ramalinga.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900