我希望我的应用程序在单击关闭(X)按钮时最小化到系统托盘。
它只会通过单击主应用程序窗口上的不同按钮/菜单或单击系统托盘上下文菜单项来关闭。
我可以使窗口在关闭时最小化到托盘。
但我面临的问题是,我现在无法关闭应用程序。
这是我的代码(它无法关闭应用程序):
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void hideToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Visible = false;
}
private void showToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Visible = true;
}
private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.DoEvents();
Application.Exit();
}
private void Form1_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;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
}