Reputation: 33078
I'm trying to create a child form that helps the user to enter data for a field in the parent form. I want this child form to be modal, but what do I need to do to make this form modal?
Is there's a different type of item I need to use?
Upvotes: 48
Views: 117618
Reputation: 5257
After you close the modal form, dispose the resources
using (Form form = new Form())
{
form.ShowDialog(this);
} // Dispose form
The using
statement ensures that Dispose
is called even if an exception occurs within the using
block.
More using statement (C# Reference)
Upvotes: 6
Reputation: 121
Call the ShowDialog method.
Form f = new Form();
f.ShowDialog(this);
For more info click this https://msdn.microsoft.com/en-us/library/aa984358(v=vs.71).aspx
Upvotes: 11
Reputation: 13077
Use the ShowDialog()
method instead of Show()
when you display the child form.
Upvotes: 25
Reputation:
As Bob mentioned, you should set Form.DialogResult
accordingly on your modal form.
Upvotes: 62