Reputation: 174
I have a main app that is able to call .net methods. My .net method starts a new thread that shows a modal form.
Now my .net method needs to disable all windows from the main app while the modal form is shown.
How can I do this?
I was thinking about the win32 method "GetWindow",, but then I would need the handle of the main-app form.
In my example you see the main app that calls the method with the modal dialog. When I click on the main app while the threadingform-dlg is open, the threadingform-dlg should blink.
Upvotes: 2
Views: 718
Reputation: 18743
foreach (Form openedForm in Application.OpenForms) {
if (openedForm.GetType() == FormToClose) {
openedForm.Hide();
}
}
Upvotes: 1
Reputation: 32437
You can get the all open windows of the application by accessing OpenForms property.
var forms = Application.OpenForms;
Upvotes: 1
Reputation: 75296
You should not show a modal form from a separate thread (you really shouldn't even show a non-modal form from a thread). Instead, display the modal form from your application's main form. If this requires moving some of your code around, so be it.
Upvotes: 3
Reputation: 59
Use the ShowDialog()
function of the form instead of Show()
. It will automatically make the form modal.
I don't know if it disables all other windows or only the calling one, try.
Upvotes: 4