工具箱找到“notifyIcon”控件,拖到主窗体中
设置显示图标,用于显示在托盘中
双击托盘图标事件
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar = true;
this.Visible = true;
this.WindowState = FormWindowState.Normal;
this.Activate();
}
}
窗体最小化事件
private void frmMain_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar = false;
this.notifyIcon.Visible = true;
}
}
窗体关闭
private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
{
notifyIcon.Dispose();
System.Environment.Exit(0);
}