本文介紹了如何向 System.Windows.Forms.MenuItem 添加圖標?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我嘗試將圖標添加到我的上下文菜單項之一,但我無法做到.有人可以幫我嗎?
I tried to add an icon to one of my context menu items, but I couldn't do it. Can anybody help me?
這是我寫的代碼:
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;
}
}
推薦答案
MainMenu/ContextMenu 已過時,您應該改用菜單條類.
MainMenu/ContextMenu are obsolete, you should use the menu strip classes instead.
改變
notifyContextMenu = new System.Windows.Forms.ContextMenu();
notifyContextMenu.MenuItems.Add("Exit");
到
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;
這篇關于如何向 System.Windows.Forms.MenuItem 添加圖標?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!