我需要以相同的方式關閉我的應用程序,無論是直接關閉還是關閉任務欄或任務管理器。我需要做一些預先設置,並在應用程序關閉之前每次自動生成日誌文件...如何管理我的應用程序關閉的方式?
例如,我在每次退出時對我的應用程序表單產生以下影響,但是當I關閉我的應用程序從任務欄或任務管理器...
System.Windows.Forms.Timer closeTimer = new System.Windows.Forms.Timer();
void lblClose_Click(object sender, System.EventArgs e)
{
closeTimer.Tick += new EventHandler(closeTimer_Tick);
closeTimer.Interval = 10;
closeTimer.Start();
}
void closeTimer_Tick(object sender, EventArgs e)
{
int a = (int)(this.Opacity * 100);
a--;
this.Opacity = ((double)a/100);
if ((this.Opacity*100) == 0)
this.Close();
}
也許這個問題會很有用:http://stackoverflow.com/questions/10579446/capturing-application-exit-event-winforms – Mansfield
'System.Windows.Forms.Form'有兩個事件'FormClosing'和'FormClosed '你可以在這種情況下使用。 – Leri
@PLB這隻會捕獲窗體關閉 - 這並不一定意味着應用程序正在關閉。 – Mansfield