2

as you can see in the code below, the form will be hidden if the deactivate event is triggered, and the form will be shown again if notifyIcon clicked, the problem is, when form state is visible, then notifyIcon is clicked, the form will be hidden and immediatly shown again, I do not want this behavior, please someone help me.

    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();
        }
    }
nyongrand
  • 618
  • 10
  • 24
  • Take a look at http://stackoverflow.com/questions/7309098/c-sharp-toggle-form-visibility-on-notifyicon-click-and-hide-it-on-click-elsewher – coolmine May 30 '13 at 03:10
  • 1
    solutions given in the question that you mentioned still have a deficiency, because if the user clicks faster than the time specified (in this case 1000ms) then the form will not be shown, I hope to be like the start menu behavior. – nyongrand May 30 '13 at 10:40
  • Note that it's ticks, not milliseconds. – coolmine May 30 '13 at 12:33
  • yes, i miss type it, i try to set as fast as 200 but still, some click not shown the form, but for a while I guess I will use this solution, at least this is fulfilling my desire a bit, thank you for pointing this to me. – nyongrand May 30 '13 at 14:08

3 Answers3

0

You should simply verify if it's visible or not.

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

Hope it could help :)

Gauthier G. Letellier
  • 3,305
  • 1
  • 16
  • 12
  • 1
    this is not working, if form is visible form will be hidden and immediatly shown again, I wish if this is as simple as this. – nyongrand May 30 '13 at 10:28
-2
private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        If (!this.isVisible)
        {
             this.Show();
             this.Activate();
        }
    }
}

Stab in dark as I am away from my side at the moment... Good luck :-)

  • 1
    this is not working, if form is visible form will be hidden and immediatly shown again, I wish if this is as simple as this. – nyongrand May 30 '13 at 10:34
-2

try this:

this.Hide();
(FormToBeDisplayed).ShowDialog();
this.Show();
coder_007
  • 187
  • 1
  • 2
  • 9