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