开发者

WindowsState Minimized is not working when NotifyIcon is used

I'm trying to show NotifyIcon when form is closed. It closed but it also closed when I click Minimized button. Here is my code.

    private void Home_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 = true;
        }
    }

    private void notifyIcon1_DoubleClick(object sender, EventArgs e)
    {
        if (this.WindowState == FormWindowState.Minimized)
  开发者_开发问答      {
            this.Show();
            this.Activate();
            this.WindowState = FormWindowState.Normal;

        }
    }

    private void Home_FormClosing(object sender, FormClosingEventArgs e)
    {   
        e.Cancel = true;
        this.WindowState = FormWindowState.Minimized;           
    }

    private void toolStripMenuItem1_Click_1(object sender, EventArgs e)
    {
        //Exit App
        notifyIcon1.Visible = false;
        Environment.Exit(0);
    }


Simply move the code from the Resize event handler to the FormClosing event handler. Also check e.CloseReason, your form needs to close when Windows shuts down.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜