views:

19

answers:

3

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.

A: 

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

DialogResult = DialogResult.OK;

Or whatever you want the result to be.

Dan
A: 

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.

Xavier Poinas
A: 

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 ).

Sindoki