在窗口的“将被销毁”事件中加入以下代码:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{notifyIcon.Visible = false }
NotifyIcon里面有一个ContextMenuStrip属性,直接设置这个属性就可以了,不要在click事件中设置,这是我以前写的一个项目中截的,粘给你看看:System.Windows.Forms.ContextMenuStrip contextMenu = new System.Windows.Forms.ContextMenuStrip()
System.Windows.Forms.ToolStripMenuItem item1 = new System.Windows.Forms.ToolStripMenuItem()
item1.Click += new EventHandler(item1_Click)
item1.Text = "显示主面板"
System.Windows.Forms.ToolStripMenuItem item2= new System.Windows.Forms.ToolStripMenuItem()
item2.Text = "退出"
item2.Click += new EventHandler(item2_Click)
contextMenu.Items.Add(item1)
contextMenu.Items.Add(item2)
this.notifyIcon.ContextMenuStrip = contextMenu
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)