Как предотвратить закрытие окна, показывая MessageBox
? (Технология: WinForms
с C#
)
Когда произойдет событие закрытия, я хочу запустить следующий код:
private void addFile_FormClosing( object sender, FormClosingEventArgs e ) {
var closeMsg = MessageBox.Show( "Do you really want to close?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
if (closeMsg == DialogResult.Yes) {
//close addFile form
} else {
//ignore closing event
}
}