Given that you indicated that you need a default error dialog , one way to do this is to transfer your check to the OnClosing event handler. In this example, closing the form is interrupted if the user answers a question in the dialog box.
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
By setting e.Cancel = true , you cannot close the form.
However, it would be better to display inline validation errors (by highlighting visible fields, displaying tooltips, etc.) and prevent the user from choosing the OK button in the first place.
ChrisF Mar 23 2018-10-23T00: 00Z
source share