Reputation: 309
I have a Main Form and a Other Form. The Main Form is always open, and at some time it will launch Other Form.
I tried:
form.TopMost = true;
But this only places the form on top. The Form behind (Main Form) still can be accessible.
How can I get the same behavior like when I do OpenFileDialog, and disable the main form behind it?
(Thanks in advance)
Upvotes: 2
Views: 1537
Reputation: 605
form.showdialog(); where form is the the top form to be launched.so while lauching the top form just add form.showdialog()
Upvotes: 0
Reputation: 51204
You need to make your form modal. To do this, use ShowDialog
instead of Show
to display it (the same way you do with a dialog).
Also, note that forms shown with ShowDialog
are not actually closed and disposed when you click their Close button, so you should dispose them manually. The usual way to handle their lifetime is to use a using
construct:
using (var form = new SomeForm())
{
form.ShowDialog();
// do stuff after the dialog is closed
}
Upvotes: 5