我写了个有托盘的程序,结果在前几次最小化和双击托盘的时候正常,测试过几次后就出现了不显示界面的现象。
图标已经设置,前几次正常。
请各位帮忙看看吧代码如下:private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Visible = true;
            this.ShowInTaskbar = true;            this.WindowState = FormWindowState.Normal;
            this.notifyIcon1.Visible = false;
            this.Activate();
        } private void frmMain_Resize(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.notifyIcon1.Visible = true;
                //this.Hide();
                this.Visible = false;
                this.ShowInTaskbar = false;
            }
        }//右键按钮显示界面
private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Visible = true;
            this.ShowInTaskbar = true;            this.WindowState = FormWindowState.Normal;
            this.notifyIcon1.Visible = false;
            this.Activate();
        }

解决方案 »

  1.   

    可以参考 http://blog.csdn.net/shellwin/archive/2010/08/02/5782487.aspx
      

  2.   

            private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                this.Show();
                this.ShowInTaskbar = true;
                notifyIcon1.Visible = false;
                this.WindowState = FormWindowState.Normal;
                this.Activate();
            }        private void Form1_Resize(object sender, EventArgs e)
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    notifyIcon1.Visible = true;
                    this.Hide();
                    this.ShowInTaskbar = false;
                }
            }
      

  3.   

    你的frmMain_Resize事件的处理是否妥当
    自己再看看
    你隐藏了
    大哥
    而且你在notifyIcon1_MouseDoubleClick有改变窗体的语句
    如果 this.WindowState = FormWindowState.Normal;引起了窗体改变
    那么你的窗体还能见吗?
    所以是你的思维错误
    只所以有时错,是因为窗体当前State的问题
    你再想想看是不是
      

  4.   

    试试这个:
    FormWindowState oldState = FormWindowState.Normal;
    private void FrmMain_SizeChanged(object sender, EventArgs e)
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    this.ShowInTaskbar = false;
                }
                else
                {
                    oldState = this.WindowState;
                }
            }private void notifyIcon1_MouseDoubleClick(object sender, EventArgs e)
            {
                this.ShowInTaskbar = true;
                this.WindowState = oldState;
                this.Show();
                cmsHide.Enabled = true;
                cmsShow.Enabled = false;
            }