点击最小化到托盘时,首先需要给NotifyIcon添加Icon属性,也就是给一个图标,不然在托盘显示空白(无显示),简单代码如下:
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Hide();
this.notifyIcon1.Visible = true;
}
}
private void notifyIcon1_MouseDown(object sender, MouseEventArgs e)
{
this.notifyIcon1.Visible = false;
this.Show();
this.WindowState = FormWindowState.Normal;
}