在Windows Form的开发中,我们经常要把应用程序最小化到系统托盘,.net可以很方便的实现,只需要在主窗体上添加一个notifyIcon控件,然后调用下面的代码片段即可:
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Visible = false;
this.notifyIcon1.Visible = true;
// FormWindowState枚举代表了窗体的三种状态。
//Maximized 最大化的窗口。
//Minimized 最小化的窗口。
//Normal 默认大小的窗口。
}
}
//为notifyIcon控件添加双击事件
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Visible = true;
this.notifyIcon1.Visible = false;
this.WindowState = FormWindowState.Normal;
}
