2

正如您在下面的代码中看到的,如果触发了 deactivate 事件,表单将被隐藏,如果单击 notifyIcon,表单将再次显示,问题是,当表单状态可见时,单击 notifyIcon,表单将被隐藏并立即再次显示,我不希望这种行为,请有人帮助我。

    private void FormMain_Deactivate(object sender, EventArgs e)
    {
        this.Hide();
    }

    private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            this.Show();
            this.Activate();
        }
    }
4

3 回答 3

0

您应该简单地验证它是否可见。

 private void FormMain_Deactivate(object sender, EventArgs e)
 {
     this.Hide();
 }

  private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
 {
   if (e.Button == MouseButtons.Left && !this.isVisible)
   {
         this.Show();
         this.Activate();
   }
 }

希望它可以帮助:)

于 2013-05-30T07:42:36.787 回答
-2
private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        If (!this.isVisible)
        {
             this.Show();
             this.Activate();
        }
    }
}

此刻我不在身边,在黑暗中刺伤......祝你好运:-)

于 2013-05-30T04:18:59.130 回答
-2

尝试这个:

this.Hide();
(FormToBeDisplayed).ShowDialog();
this.Show();
于 2013-05-30T07:21:55.807 回答