title: Passing value from dialog form to main form
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4887820/how-do-you-pass-an-object-from-form1-to-form2-and-back-to-form1">How do you pass an object from form1 to form2 and back to form1?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm used to passing variables between windows forms by simply passing them as a parameter.
  Now I have a form that is already open (let's call it <code>FormMain</code>), and another form that should act like a dialog (<code>FormTask</code>). The user cannot interact with the main form until he has filled in the information on <code>FormTask</code>. <code>FormTask</code> simply contains a single textbox, and the value of this textbox should be returned to <code>FormMain</code>, and kept track of as a variable. <code>FormTask</code> requires a parameter <code>exerciseType</code>. When <code>FormTask</code> opens it checks the value of this parameter and sets the default value of the textbox accordingly. This already works, I'm just kind of clueless on how to return my string value to the already open <code>MainForm</code>.
  These dialogs only seem to be able to return <code>DialogResults</code>, which isn't what I'm after. I'm not too experienced either, and I'd rather avoid fumbling around to make my own custom dialog.</p>
  
  <p><strong>FormMain:</strong></p>
  
  <pre><code>FormTask formTask = new FormTask(exerciseType);
  formOpgaveInvoker.ShowDialog();
  </code></pre>
  
  <p><strong>FormTask:</strong></p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      string opgave = textBoxOpgave.Text;
      // return string value to MainForm here
  }
  </code></pre>