我试图给我的一个上下文菜单项添加一个图标,但我做不到。有谁能够帮助我?如何将图标添加到System.Windows.Forms.MenuItem?
下面是我写的代码:
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;
}
}
嗯,这不是真的。是的,“Strip”类更新,但它们会生成菜单,*在Windows Vista及更高版本上看起来*完全可恶。而不是要求Windows绘制菜单,它们都是用.NET代码自定义绘制的。它们在Windows XP中看起来不错,并且它们与Office XP中使用的自定义绘制菜单相匹配,但从那以后,技术发生了很大的变化。使用这些丑陋的菜单试图避免过时看起来像对我来说是一个相当愚蠢的决定。你的应用程序永远不会在现代版本的Windows上看起来不错。 –
尽管本机包装在Windows Vista及更高版本上看起来效果更好,但通过自定义渲染器可以在条带类中实现同样的效果,http://code.google.com/p/szotar/source/browse/trunk/Client/ Szotar.WindowsForms/Base/NativeToolStripRenderer.cs –
甚至没有接近...(我已经尝试过了,重新编写了它,调整了它,尝试了更多,不一样,更糟糕的是,不管你做了多少它看起来像原生菜单,它不会像原生菜单那样行为。)但的确,更好的... –