本文介紹了如何向 System.Windows.Forms.MenuItem 添加圖標(biāo)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我嘗試將圖標(biāo)添加到我的上下文菜單項(xiàng)之一,但我無法做到.有人可以幫我嗎?
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 已過時(shí),您應(yīng)該改用菜單條類.
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
最后附上上下文菜單條以通知圖標(biāo),
Finally attach the context menu strip to notify icon,
notifyIcon.ContextMenuStrip = notifyContextMenu;
這篇關(guān)于如何向 System.Windows.Forms.MenuItem 添加圖標(biāo)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!