can Form return value?

  • Thread starter Thread starter VMI
  • Start date Start date
V

VMI

I have one Windows Form form1 with a button, and when I press that button,
it'll display another Form form2 whose only purpose is for the user to enter
a path. Is it possible for form2 to return that string value back to form1,
similar to the MessageBox?

Thanks.
 
VMI said:
I have one Windows Form form1 with a button, and when I press that button,
it'll display another Form form2 whose only purpose is for the user to enter
a path. Is it possible for form2 to return that string value back to form1,
similar to the MessageBox?

Sure, its a dialog. You just use the first form in dialog mode
(ShowDialog, rather than Show) and then use either a property or public
member variable to return data to the calling app...

class Form1...
class Form2...


private void Form1_ShowDialog()
{
Form2 f2 = new Form2();
if ( f2.ShowDialog() == DialogResult.OK )
{
string path = f2.FileName; // Property in form2
}
}

matt
}
 
Back
Top