問題是,「確定要關閉嗎?」的消息框?會彈出,但是當我點擊「否」時,它仍然繼續關閉程序。有什麼建議麼? 這裏是我的代碼:單擊「X」按鈕時要求確認
protected override void OnFormClosing(FormClosingEventArgs e)
{
CloseCancel();
}
public static void CloseCancel()
{
const string message = "Are you sure that you would like to cancel the installer?";
const string caption = "Cancel Installer";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
Environment.Exit(0);
}
這就是它,但你是過分的東西。爲什麼'CanClose(false)'而不是'CanClose()'? – Otiel
試過了,你不需要CanClose()方法中的參數,恭喜第一個答案 –