WPF窗體最小化到任務欄


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();
            }
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM