winform程序托盤處理

對於winform程序托盤處理。首先添加NotifyIcon控件和ContextMenuStrip控件,把ContextMenuStrip控件關聯到NotifyIcon,然後編寫各個事件處理代碼
如下:
        
#region 托盤處理
private bool _CloseApplication = false;
        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!_CloseApplication)
            {
                e.Cancel = true;
                this.Hide();
                this.ShowInTaskbar = true;
            }
        }
        //打開
        private void ToolStripMenuItemOpen_Click(object sender, EventArgs e)
        {
            this.Show();
            this.Activate();
        }
        //退出
        private void ToolStripMenuItemClose_Click(object sender, EventArgs e)
        {
            _CloseApplication = true;
            Application.Exit();
        }
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();
            this.Activate();
        }
        #endregion
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章