Skip to content

Instantly share code, notes, and snippets.

@diaolizhi
Created October 21, 2018 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diaolizhi/b0a03305cd7f5c78f7fe2414aa7d3bb5 to your computer and use it in GitHub Desktop.
Save diaolizhi/b0a03305cd7f5c78f7fe2414aa7d3bb5 to your computer and use it in GitHub Desktop.
C# winform 关闭窗口前确认
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = (MessageBox.Show("Sure?",
"Exit",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes);
DialogResult result = MessageBox.Show("提示", "确定退出吗?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment