一,在工具箱添加notifyIcon控件,contextMenustrip控件
二,設定屬性Icon ,Text ,visable(true),contextMenustrip,
三,添加窗體Closing()事件,加入代碼:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)//當使用者點選窗體右上角X按鈕或(Alt + F4)時 發生
{
e.Cancel = true;
this.ShowInTaskbar = false;
this.Hide();
}
}
四,添加contextMenu點選事件:
private void 顯示ToolStripMenuItem_Click(object sender, EventArgs e)//實作重新顯示窗體
{
if (this.Visible == false)
this.Visible = true;
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)//實作關閉整個窗體
{
Application.Exit();//通過Application類的靜态方法Exit()退出應用程式
}
五,實作滑鼠輕按兩下工作列圖示顯示程式界面:
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.Visible == false)
this.Visible = true;
}