4thSpace
4thSpace

Reputation: 44352

How do dismiss modal dialogue form?

I'm using code from this example: Messagebox with input field

Once the user clicks the button on the form, nothing happens. The form remains. Do I need to wireup something for the modal to go away so I can get the textbox result?

public void ShowMyDialogBox()
{
   Form2 testDialog = new Form2();

   // Show testDialog as a modal dialog and determine if DialogResult = OK.
   if (testDialog.ShowDialog(this) == DialogResult.OK)
   {
      // Read the contents of testDialog's TextBox.
      this.txtResult.Text = testDialog.TextBox1.Text;
   }
   else
   {
      this.txtResult.Text = "Cancelled";
   }
   testDialog.Dispose();
}

Upvotes: 0

Views: 173

Answers (1)

Dave
Dave

Reputation: 1055

To get the form to close, you'll need to call Close(); within the button clicked event on Form2.

Upvotes: 2

Related Questions