我希望我的應用程序能夠在單擊關閉(X)按鈕時使系統托盤最小化。C#應用程序關閉問題
只有通過在主應用程序窗口上單擊不同的按鈕/菜單或單擊系統托盤上下文菜單項才能關閉它。
我可以使窗口最小化到關閉的托盤。
但是我面對的問題是,我現在無法關閉應用程序。
這是我的代碼(這是無法關閉應用程序):
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;
}
}