0
当窗体关闭时,我试图显示NotifyIcon。它关闭了,但当我点击最小化按钮时它也会关闭。这是我的代码。当使用NotifyIcon时,WindowsState最小化不起作用
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事件不好检查windowstate。 – Reniuz
如果是的话我可以使用哪种事件?谢谢:) – novasaint