讓視窗程式只在 system tray 中顯示, 不會出現在工作列(task bar)中, 也不會出現在 alt-tab 清單裡頭
In system tray, not in task bar
//必須加入一個 notifyIcon 物件, 且將Visible屬性設定為 True //表單(form)的 WindowStat 設定為 Minimized, ShowInTaskBar 設定為 False #region 設定為常駐在 tray 中 private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.WindowState = FormWindowState.Normal; this.ShowInTaskbar = true; // Activate the form. this.Activate(); } else if (this.WindowState == FormWindowState.Normal) { this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; notifyIcon1.BalloonTipTitle = "APP Hidden"; notifyIcon1.BalloonTipText = "Your application has been minimized to the taskbar."; notifyIcon1.ShowBalloonTip(3000); } } #endregion public Class1() { InitializeComponent(); this.WindowState = FormWindowState.Minimized; }
設定成不會在 alt-tab 清單中出現
using System.Runtime.InteropServices; // 設定成不會在 alt-tab list 中出現 [DllImport("user32.dll")] public static extern int SetWindowLong(IntPtr window, int index, int value); [DllImport("user32.dll")] public static extern int GetWindowLong(IntPtr window, int index); const int GWL_EXSTYLE = -20; const int WS_EX_TOOLWINDOW = 0x00000080; const int WS_EX_APPWINDOW = 0x00040000; public Class1() { InitializeComponent(); // 設定成不會在 alt-tab list 中出現 int windowStyle = GetWindowLong(Handle, GWL_EXSTYLE); SetWindowLong(Handle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDOW); }