.net - How to add an icon to System.Windows.Forms.MenuItem? -
i tried add icon 1 of context menu items, couldn't it. can me?
here's 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 add icon context menu item? } notifyicon.contextmenu = notifycontextmenu; } }
mainmenu/contextmenu obsolete, should use 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 context menu strip notify icon,
notifyicon.contextmenustrip = notifycontextmenu;
Comments
Post a Comment