Skip to content

Instantly share code, notes, and snippets.

@joebuschmann
Created December 18, 2014 20:05
Show Gist options
  • Select an option

  • Save joebuschmann/6a10c5813be82e46cc5a to your computer and use it in GitHub Desktop.

Select an option

Save joebuschmann/6a10c5813be82e46cc5a to your computer and use it in GitHub Desktop.
Prevent a dialog from closing by setting Form.DialogResult to None
private void btnOK_Click(object sender, EventArgs e)
{
if (Validate())
{
// There's no need to explicitly hide the form
// because the button's DialogResult property
// has a value of DialogResult.OK
// Details elided...
}
else
{
// Set the value of the form's DialogResult property
// to DialogResult.None to prevent the form from closing.
this.DialogResult = DialogResult.None;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment