首页 文章

最小化托盘的问题

提问于
浏览
0

在我的Windows窗体应用程序(C#)中,我有这样的代码:

private void frm_main_Resize(object sender, EventArgs e)
    {
        if ((this.WindowState == FormWindowState.Minimized) && (checkBox1.Checked))
        {
            this.ShowInTaskbar = false;

            notifyIcon1.Visible = true;
        }
    }

    private void notifyIcon1_DoubleClick(object Sender, EventArgs e)
    {
        if (this.WindowState == FormWindowState.Minimized)
        {
            this.WindowState = FormWindowState.Normal;
        }
        else
        {
            this.WindowState = FormWindowState.Minimized;
        }

        this.Activate();
    }

我的publick表单有双击处理程序 notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);

当最小化的应用程序仍在任务栏中出现时,如何更改?我希望在最小化状态下它只在系统托盘中 . 为什么这个cos deosnt工作?

1 回答

  • 2

    我在我的项目中使用类似的代码,它正在工作,你不需要隐藏和显示:

    private void frm_main_Resize(object sender, EventArgs e)
    {
        if (this.WindowState == FormWindowState.Minimized && checkBox1.Checked)
        {
            this.ShowInTaskbar = false;
            notifyIcon1.Visible = true;
        }
    }
    

    也尝试处理 MouseClick 事件而不是 DoubleClick

    private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
      {
         if (e.Button == System.Windows.Forms.MouseButtons.Left && e.Clicks == 2)
         {
            this.WindowState = FormWindowState.Normal;
            this.ShowInTaskbar = true;
            notifyIcon1.Visible = false;
            this.Activate();
         }
      }
    

相关问题