我认为您可以在其中添加图像,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;
谢谢,
我希望你觉得这有帮助:)