Click the close button upper right corner of the form when the confirmation pop-up window, click OK to exit, click Cancel, Cancel to exit, pay attention, do not confirm the lower write this.Close (); so there will be an infinite loop and can not exit the form
Example code:
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (MsgBox.ShowQuestion("退出系统吗?") == DialogResult.OK)
{
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}
Reproduced in: https: //my.oschina.net/dongri/blog/610899