WinForm窗体的托盘最小化实现代码

//窗体最小化时候将窗体隐藏掉,同时让托盘控件显示
private void Form1_SizeChanged(object sender, EventArgs e)
{
if(this.WindowState == FormWindowState.Minimized)
{
this.Hide();
this.notifyIcon1.Visible = true;
}
}

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
ShowDlg();
}

private void MinToIcon()
{
this.Hide();
this.ShowInTaskbar = false;
this.notifyIcon1.Visible = true;
}
private void ShowDlg()
{
this.Show();
this.ShowInTaskbar = true;
this.notifyIcon1.Visible = false;
}
//这里添加了右键属性
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
ShowDlg();
}

private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Dispose(true);
Application.ExitThread();
}
原文地址:https://www.cnblogs.com/liumengchen-boke/p/5639395.html