我試圖給我的一個上下文菜單項添加一個圖標,但我做不到。有誰能夠幫助我?如何將圖標添加到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 –
甚至沒有接近...(我已經嘗試過了,重新編寫了它,調整了它,嘗試了更多,不一樣,更糟糕的是,不管你做了多少它看起來像原生菜單,它不會像原生菜單那樣行爲。)但的確,更好的... –