How to add an icon to System.Windows.Forms.MenuItem?
.net, contextmenu, menu, winforms
Solution
MainMenu/ContextMenu are obsolete, you should use the menu strip classes instead.
Change
notifyContextMenu = new System.Windows.Forms.ContextMenu();
notifyContextMenu.MenuItems.Add("Exit");
to
notifyContextMenu = new System.Windows.Forms.ContextMenuStrip();
var exitMenuItem = notifyContextMenu.Items.Add("Exit");
exitMenuItem.Image = ...;
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripitem.image.aspx
Finally attach the context menu strip to notify icon,
notifyIcon.ContextMenuStrip = notifyContextMenu;
Problem
I tried to add an icon to one of my context menu items, but I couldn't do it. Can anybody help me? Here's the code I've written: ``` private System.Windows.Forms.ContextMenu notifyContextMenu; private void foo() { if (notifyIcon == null) { notifyIcon = new System.Windows.Forms.NotifyIcon(); } if (notifyContextMenu == null) { notifyContextMenu = new System.Windows.Forms.ContextMenu(); notifyContextMenu.MenuItems.Add("Exit"); // How do I add an icon to this context menu item? } notifyIcon.ContextMenu = notifyContextMenu; } } ```