C# 使用NotifyIcon时,Windows状态最小化不起作用
我试图在窗体关闭时显示NotifyIcon。它关闭了,但当我点击最小化按钮时它也关闭了。这是我的密码C# 使用NotifyIcon时,Windows状态最小化不起作用,c#,winforms,notifyicon,C#,Winforms,Notifyicon,我试图在窗体关闭时显示NotifyIcon。它关闭了,但当我点击最小化按钮时它也关闭了。这是我的密码 private void Home_Resize(object sender, EventArgs e) { if (FormWindowState.Minimized == this.WindowState) { notifyIcon1.Visible = true; notifyIcon1.Sh
private void Home_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == this.WindowState)
{
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(500);
this.Hide();
}
else if (FormWindowState.Normal == this.WindowState)
{
notifyIcon1.Visible = true;
}
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Show();
this.Activate();
this.WindowState = FormWindowState.Normal;
}
}
private void Home_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
}
private void toolStripMenuItem1_Click_1(object sender, EventArgs e)
{
//Exit App
notifyIcon1.Visible = false;
Environment.Exit(0);
}
只需将代码从Resize事件处理程序移动到FormClosing事件处理程序。另请检查e.CloseReason,当Windows关闭时,您的表单需要关闭。您在最小化表单时隐藏了表单,因此它实际上没有关闭。我认为调整大小事件不适合检查Windows状态。如果是,我可以使用哪个事件?谢谢:)