Old school trick that I forgot

Posted by DavidMadden on Geeks with Blogs See other posts from Geeks with Blogs or by DavidMadden
Published on Wed, 28 Nov 2012 13:42:58 GMT Indexed on 2012/11/28 17:06 UTC
Read the original article Hit count: 223

Filed under:
If you have to support some older Winforms you might like to remember this.  When opening a MessageBox to display that the user entered incorrect information, if you are doing so from a dialog, catch the DialogResult of the MessageBox and then set 

this.DialogResult = DialogResult.None;

 to prevent the dialog from closing if you want the user to try again.  Otherwise, it will close the dialog box and return to the section of code that called it.

Note:  You do not have to catch the DialogResult from the MessageBox.  You can still set this after the return from the call to the MessageBox.  Just make sure to do either but exiting the body of the dialog itself.

© Geeks with Blogs or respective owner