0

我试图在表单关闭时显示 NotifyIcon 。它关闭了,但是当我单击最小化按钮时它也关闭了。这是我的代码。

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

1 回答 1

1

只需将代码从 Resize 事件处理程序移动到 FormClosing 事件处理程序。还要检查 e.CloseReason,当 Windows 关闭时,您的表单需要关闭。

于 2011-08-30T09:13:46.730 回答