我認爲你可以在ContextMenuStrip
之內添加圖片,但是用ContextMenu
不能這樣做。下面是關於如何做到這一點
示例一個簡單的例子
private void Form1_Load(object sender, EventArgs e)
{
Image ContextMenuStripItemImages = Image.FromFile(@"D:\Resources\International\Picrofo_Logo.png"); //Set the image from the path provided
NotifyIcon trayIcon;
ContextMenuStrip trayMenu;
trayMenu = new ContextMenuStrip();
trayMenu.Items.Add("Login", ContextMenuStripItemImages).Click += new EventHandler(Login_Click); //Create a new item in the context menu strip and link its Click event with Login_Click
trayMenu.Items.Add("LogOut", ContextMenuStripItemImages).Click += new EventHandler(LogOut_Click); //Create a new item in the context menu strip and link its Click event with LogOut_Click
trayIcon = new NotifyIcon();
trayIcon.ContextMenuStrip = trayMenu; //Set the ContextMenuStrip of trayIcon to trayMenu
}
private void Login_Click(object sender, EventArgs e)
{
//Do something when Login is clicked
}
private void LogOut_Click(object sender, EventArgs e)
{
//Do something when LogOut is clicked
}
注意:當您準備好顯示你NotifyIcon
給用戶,你可以使用NotifyIcon.Visible = true;
謝謝,
我希望你覺得這有幫助:)
WinForms或WPF? –
您的答案在這裏http://stackoverflow.com/questions/6555691/how-to-add-icon-to-context-menu-in-c-sharp-windows-form-application –