日期:2014-05-20  浏览次数:20721 次

程序无法退出,求解!
我程序Form1上有NotifyIcon1,包含ContentMenuStrip1,里面含 <退出> 选项,

现在我关闭Form1,在FormClosing事件里写入
e.Cancel=true;
this.Hide();

主界面退出了,NotifyIcon1不退出,现我再点NotifyIcon1上的 <退出> 按钮,结果程序不退出,退出代码是:
Application.Exit();

请问如何解决,我要点 <退出> 时程序能退出,急....

------解决方案--------------------
不知道是不是這個意思
Try
If MsgBox( "你確定退出本系統嗎? ", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
Application.Exit()
Else
e.Cancel = True
End If
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Exclamation, "System Informaiton! ")
End Try
------解决方案--------------------
现在我关闭Form1,在FormClosing事件里写入
e.Cancel=true;
this.Hide();

主界面退出了,NotifyIcon1不退出,现我再点NotifyIcon1上的 <退出> 按钮,结果程序不退出,退出代码是:
Application.Exit();

还是会引发
FormClosing事件,e.Cancel里加个判断退出从哪发出的
------解决方案--------------------
判断一个是哪里调用的FormClosing事件,我的测试代码

bool ex;
private void Form1_Load(object sender, EventArgs e)
{
ex = false;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (ex)
{
Application.Exit();
}
else
{
e.Cancel = true;
this.Hide();
}
}
private void toolStripMenuItem1_Click(object sender, EventArgs e) //NotifyIcon1的ContentMenuStrip1
{
ex = true;
Application.Exit();
}