You could also create a Subclass of Form...
public class FormWithResult : Form
{
protected object FormResult { get; set; }
public DialogResult ShowDialog(out object result)
{
DialogResult dr = ShowDialog();
result = FormResult;
return dr;
}
public DialogResult ShowDialog(out object result, IWin32Window win)
{
DialogResult dr = ShowDialog(win);
result = FormResult;
return dr;
}
public void Return(object result)
{
FormResult = result;
Close();
}
}
Then you can write this to Call a modal form and retrieve a result
popup p = new popup();
object result;
p.ShowDialog(out result);
MessageBox.Show((string)result);
And in your popup form you can either do:
FormResult = textBox1.Text;
Close();
OR
Return(textBox1.Text);
To Close the form and return the value.
Subclassing Form has drawbacks as well of course, but I'll throw this out as another solution.
As a side not, a generic version of this where you could Strongly type the return value would be much better if it weren't for this limitation at design time: Visual Studio 2008 Winform designer fails to load Form which inherits from generic class
If you wanted Asynchronous results obviously this would have to be tweaked. I assume you are using Modal popups.