WPF程序也可以很輕松的實現類似QQ那樣最小化到任務欄的功能。
WindowState ws; WindowState wsl; NotifyIcon notifyIcon; #region Constructions public MainWindow() { InitializeComponent();//顯示托盤。 icon(); //保證窗體顯示在上方。 wsl = WindowState; } #endregion private void icon() { this.notifyIcon = new NotifyIcon(); this.notifyIcon.BalloonTipText = "Hello, 文件監視器"; //設置程序啟動時顯示的文本 this.notifyIcon.Text = "文件監視器";//最小化到托盤時,鼠標點擊時顯示的文本 this.notifyIcon.Icon = new System.Drawing.Icon("Downloads.ico");//程序圖標 this.notifyIcon.Visible = true; notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick; this.notifyIcon.ShowBalloonTip(1000); } private void OnNotifyIconDoubleClick(object sender, EventArgs e) { this.Show(); WindowState = wsl; } private void Window_StateChanged(object sender, EventArgs e) { ws = WindowState; if (ws == WindowState.Minimized) { this.Hide(); } }