Reputation: 6766
I have a program which displays a dialog box(which is a new form).
Now what i want is to stop the execution of the program until user has entered password and pressed Ok Button on the other form.
Problem is whenever i display the dialog box. The underlying program doesnt stop execution and continues anyway.
How can i stop the execution of program until user has entered username and password and submitted them to the main form.
Upvotes: 0
Views: 241
Reputation: 236328
Use otherForm.ShowDialog()
method when displaying other form to user:
using(var otherForm = new OtherForm())
{
var result = otherForm.ShowDialog(); // main form stops here
if (result == DialogResult.OK)
{
// user entered text and pressed OK button on other form
}
}
Form.ShowDialog method shows the form as a modal dialog box. When this method is called, the code following it is not executed until after the dialog box is closed.
Upvotes: 2