我正在製作一個C#Windows窗體應用程序。我試圖在按下「X」或「關閉」按鈕以使其不在應用程序中時彈出一個消息框。這是我迄今爲止所做的,我不知道它有什麼問題。當我點擊關閉按鈕時,運行消息框時不顯示。任何幫助,將不勝感激。謝謝。C#Windows窗體應用程序關閉
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
{
if (this.DialogResult == DialogResult.Cancel)
{
if (MessageBox.Show("Do you want to save changes to the data?",
"MktAuthorizationData",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
e.Cancel = true;
// Do Something
}
}
}
您是否將事件處理程序代碼綁定到Form_Closing事件? – Steve
你肯定這種方法綁定到'MainWindow'的FormClosing事件嗎? – AntiTcb
我不知道這意味着什麼。我不這麼認爲,我會如何去做。 – Satish