对于winform程序托盘处理。首先添加NotifyIcon控件和ContextMenuStrip控件,把ContextMenuStrip控件关联到NotifyIcon,然后编写各个事件处理代码
如下:
#region 托盘处理
private bool _CloseApplication = false;
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (!_CloseApplication)
{
e.Cancel = true;
this.Hide();
this.ShowInTaskbar = true;
}
}
//打开
private void ToolStripMenuItemOpen_Click(object sender, EventArgs e)
{
this.Show();
this.Activate();
}
//退出
private void ToolStripMenuItemClose_Click(object sender, EventArgs e)
{
_CloseApplication = true;
Application.Exit();
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
this.Activate();
}
#endregion