0

I try to Minimize my winform application into system tray and when minimize my application it still open in task bar and not in system tray and close automatic after few seconds i have added NotifyIcon control and register to Resize event:

    private void MainWin_Resize(object sender, EventArgs e)
    {
        if (FormWindowState.Minimized == this.WindowState)
        {
            notifyIcon1.Visible = true;
            notifyIcon1.ShowBalloonTip(500);
            this.Hide();
        }
        else if (FormWindowState.Normal == this.WindowState)
        {
            notifyIcon1.Visible = false;
        }
    }
user3271698
  • 145
  • 3
  • 9
  • 19
  • How to fix it ? (did you read what i have wrote ?) – user3271698 Feb 18 '14 at 13:59
  • you can see http://stackoverflow.com/questions/1297028/having-the-application-minimize-to-the-system-tray-when-button-is-clicked – Akrem Feb 18 '14 at 13:59
  • http://stackoverflow.com/questions/46918/whats-the-proper-way-to-minimize-to-tray-a-c-sharp-winforms-app – Akrem Feb 18 '14 at 14:00
  • In the first link: it mention to register to window state change event - what exactly this event ? (i didn't find this event) – user3271698 Feb 18 '14 at 14:04
  • You've only stated what are you trying to achieve. You did not provide any information about what's wrong with your code or if you get any errors. Also please use search button and do not duplicate questions, that were previously explained. You can find window state change in the events panel or use it manually in the form's body same way as you do with your `MainWin_Resize` method. It's just better to only fire the method on state changes instead of size changes. TBH I'm not even sure if Resize event occurs on state change. – Tarec Feb 18 '14 at 14:09
  • i don't know that wrong with my cod but my application is closed automatic after few seconds – user3271698 Feb 18 '14 at 14:10

1 Answers1

2

Try this:

private void MainForm_Resize(object sender, EventArgs e)
    {
        switch (this.WindowState)
        {
            case FormWindowState.Maximized:
                this.ShowInTaskbar = true;
                break;
            case FormWindowState.Minimized:
                this.ShowInTaskbar = false;
                break;
            case FormWindowState.Normal:
                this.ShowInTaskbar = true;
                break;
            default:
                break;
        }
    }
Jenda Matejicek
  • 151
  • 3
  • 14