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

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

4

1 回答 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();
     }
  }
于 2013-01-07T21:31:34.697 回答