你從來沒有顯示什麼在通知區域。跟蹤代碼並嘗試查看發生了什麼。我已添加一些評論:
private void button6_Click(object sender, EventArgs e)
{
// When button 6 is clicked, minimize the form.
this.WindowState = FormWindowState.Minimized;
}
private void Form_Resize(object sender, EventArgs e)
{
// Catch the case where the form is minimized, including but not limited to
// clicks on button 6.
if (WindowState == FormWindowState.Minimized)
{
// In that case, hide the form.
this.Hide();
}
}
private void notifyIcon_Click(object sender, EventArgs e)
{
// If the notification icon is clicked, reshow the form as a normal window.
this.Show();
this.WindowState = FormWindowState.Normal;
}
現在注意問題所在?當表格被最小化時,你所做的就是隱藏它。你永遠不會告訴NotifyIcon
顯示其圖標!其Visible
property的默認值是false
。您必須將其設置爲true
以使圖標顯示出來,並且false
可以讓它消失。
所以修改代碼如下:
private void Form_Resize(object sender, EventArgs e)
{
// Catch the case where the form is minimized, including but not limited to
// clicks on button 6.
if (WindowState == FormWindowState.Minimized)
{
// In that case, hide the form.
this.Hide();
// And display the notification icon.
notifyIcon.Visible = true;
// TODO: You might also want to set other properties on the
// notification icon, like Text and/or Icon.
}
}
private void notifyIcon_Click(object sender, EventArgs e)
{
// If the notification icon is clicked, reshow the form as a normal window.
this.Show();
this.WindowState = FormWindowState.Normal;
// And hide the icon in the notification area.
notifyIcon.Visible = false;
}
你正在嘗試做什麼? – Mogli 2013-04-22 07:52:13
他正試圖隱藏應用程序,在系統托盤 – Pyromancer 2013-04-22 07:53:46
是的,我需要的應用上按下按鈕,只顯示disapear在系統托盤中 – Connor 2013-04-22 07:54:35