關閉窗口時實現點擊確認退出,點擊取消返回
时间:2011-06-09 来源:下一站╰垨候
1、单窗体
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if(MessageBox.Show("是否退出本系统?","确认...",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
{
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}
2、多窗体
private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
DialogResult result;
result = MessageBox.Show("您确定要退出系统吗?","请确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
if (result == DialogResult.OK)
{
foreach(Form frm in this.MdiChildren)
{
frm.Close();
}
Application.Exit();
}
else
e.Cancel = true;
}