user3271698
user3271698

Reputation: 145

Minimize my winform application into system tray

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

Upvotes: 0

Views: 143

Answers (1)

Jenda Matejicek
Jenda Matejicek

Reputation: 151

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

Upvotes: 2

Related Questions