0

In my windows forms application (C#) I have such code:

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

My publick form has Double click handler notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);

When minimized app still apears in taskbar, how to change that? I want that on minimized state it only would be in system tray. Why does this coce deosnt work?

Tautvydas
  • 1,268
  • 7
  • 19
  • 33

1 Answers1

2

I'm using similar code in my project which is working and you don't need hide and show:

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

Also try to handle MouseClick Event instead of 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();
     }
  }
VladL
  • 12,769
  • 10
  • 63
  • 83
  • For show application from tray is better to use event `MouserDoubleClick`. That event to show application use such programs as Skype, Microsoft Security Essentials, Origin and many other programs. – Epsil0neR Jan 07 '13 at 21:35
  • @Epsil0neR how do you know what they are using? they are not open source. Clicking twice on them doesn't mean they are using DoubleClick event – VladL Jan 07 '13 at 21:38
  • That doesn't make a sence. Many programs you can't show from tray with single click, so in that case he should use event `MouseDoubleClick`. – Epsil0neR Jan 07 '13 at 21:42
  • @Epsil0neR please look at my code better, I'm handling double click in my function. If the thing would be so obvious, the OP's code would work. Btw. there are 2 events, DoubleClick and MouseDoubleClick. Which would you use? – VladL Jan 07 '13 at 21:46
  • I tryed event `MouseClick` and I saw, that e.Cliks alvays are equal 1, i even can't get e.clicks > 1 with mouseclicker application, so your code won't work properly. I used 2 labels in WinForm with MouseClick event that code is here: http://pastebin.com/QcjSAxaC – Epsil0neR Jan 07 '13 at 21:59