2013-05-30 139 views
2

隐藏,如下面代码中所示,如果停用事件被触发,窗体将被隐藏,如果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(); 
     } 
    } 
+0

在http://stackoverflow.com/questions/7309098/c-sharp-toggle-form-visibility-on-notifyicon-click-and-看看hide-it-on-click-elsewher – coolmine

+1

在你提到的问题中给出的解决方案仍然存在缺陷,因为如果用户点击的速度比指定的时间更快(在这种情况下为1000毫秒),那么表单将不会显示,我希望就像开始菜单的行为一样。 – nyongrand

+0

请注意,它是刻度,而不是毫秒。 – coolmine

回答

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

刺在黑暗的,因为我从我身边离开的那一刻...祝你好运:-)

+1

这是行不通的,如果窗体是可见的,窗体将被隐藏并立即显示出来,我希望这是如此简单。 – nyongrand

-2

试试这个:

this.Hide(); 
(FormToBeDisplayed).ShowDialog(); 
this.Show(); 
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(); 
    } 
} 

希望它可以帮助:)

+1

这是行不通的,如果窗体可见窗体将被隐藏并立即显示,我希望这是如此简单。 – nyongrand