ShowInTaskbar = false(不在工作列顯示)。notifyIcon1,設定 Icon 屬性指定托盤圖示。this.SizeChanged += new EventHandler(Form1_SizeChanged);
private void Form1_SizeChanged(object sender, EventArgs e) {
if (this.WindowState == FormWindowState.Minimized) {
this.Hide();
this.notifyIcon1.Visible = true;
}
}
private void notifyIcon1_Click(object sender, EventArgs e) {
this.Visible = true;
this.WindowState = FormWindowState.Normal;
this.notifyIcon1.Visible = false;
}
ContextMenu,設定 notifyIcon1.ContextMenu,選單項加入「顯示」、「退出」等動作。Hide() 隱藏表單但進程持續運行。NotifyIcon.Visible 控制托盤圖示顯示/隱藏。WindowState = Normal 並隱藏托盤圖示。