winform显示系统托盘,双击图片图表显示窗体,退出窗体是否提示

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result = MessageBox.Show("是否退出?选否,最小化到托盘", "操作提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {

                this.Dispose();
                Application.Exit();
            }
            else
            {
                e.Cancel = true;
                this.WindowState = FormWindowState.Minimized;
                this.Visible = false;
                this.sysicon.Visible = true;
                ShowSysIcon();
            }  
            
        }
        private void ShowSysIcon()
        {
            int tipShowMilliseconds = 1000;
            string tipTitle = "服务运行中";
            string tipContent = "********管理系统";
            ToolTipIcon tipType = ToolTipIcon.Info;
            sysicon.ShowBalloonTip(tipShowMilliseconds, tipTitle, tipContent, tipType);
        }
上面 的方法是窗体关闭事件
下面 sysicon是拖入窗体的NotifyIcon控件,这个是该控件的双击事件
private void sysicon_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.Visible)
            {
                this.WindowState = FormWindowState.Minimized;
                this.sysicon.Visible = true;
                this.Hide();
            }
            else
            {
                this.Visible = true;
                this.WindowState = FormWindowState.Normal;
                this.Activate();
            }
        }

 

posted @ 2018-05-15 16:40  大da脸  阅读(467)  评论(0编辑  收藏  举报