Tutorial :How to return the result of dialog window work in the moment of its closing?



Question:

Everyone knows the MessageBox.Show() method, that returns DialogResult value after dialog closed. How can I implement such a method in my dialog class?

class MyDialog : Form {

public static MyDialogResult Show() {};  

}

The problem, as you can guess, is that the method returns a value only after user clicks some button in the dialog.


Solution:1

You can also set the DialogResult property on a button. If that button is clicked then the specified value will be returned by the ShowDialog() method.


Solution:2

In your handler which closes your dialog, put this before closing:

DialogResult = DialogResult.OK;  

Or whatever you want the result to be.


Solution:3

Very useful answers. Thanks! But I've solved my problem yet, using mutex. It provides ability to return results of different types. So, my showDialog() method returns a string ).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »