How do I pass a value from a child back to the parent form?

Jayne M picture Jayne M · Nov 11, 2008 · Viewed 99.4k times · Source

How do I pass a value from a child back to the parent form? I have a string that I would like to pass back to the parent.

I launched the child using:

FormOptions formOptions = new FormOptions();
formOptions.ShowDialog();

Answer

Mitch Wheat picture Mitch Wheat · Nov 11, 2008

Create a property (or method) on FormOptions, say GetMyResult:

using (FormOptions formOptions = new FormOptions())
{
    formOptions.ShowDialog();

    string result = formOptions.GetMyResult;

    // do what ever with result...
}