C# : Returning values on form close

TheDude05

Limp Gawd
Joined
Jan 27, 2005
Messages
393
I have a form and I want it to return some values back to the form it was instanced from when it closes. (like the vb.net inputbox class) How do I do that?
 
It's pretty easy. When you call the form, use the Form.ShowDialog() method instead of Form.Show(). That way you can check if the OK button was used to close the form, and then access public fields in the form.

Code:
MyForm frm = new MyForm()
int FormReturn;

if(frm.ShowDialog() == DialogResult.OK)
{
   this.FormReturn = frm.ReturnCode;
}

Hope that makes sense.
 
Or, just use a member variable or member function. This is particularly applicable if you want to have more than an integer come back from the subordinate form.
 
Back
Top