I am trying to use the code in this article that lets you know when your app is idle..
This code works great if your application has only one form. You call Application2.Run(myOnlyForm)
on it and all messages get routed through the filters in Application2.
However if at any point you call mySecondForm.ShowDialog()
that dialog does not get its messages filtered through Application2.
Is there any way (with out bad side effects) to get the messages on mySecondForm
to go through the `Application2' event filters?
I have tried:
- Changing
mySecondForm.ShowDialog
toApplication2.Run(mySecondForm)
.
- This causes the window to not clean up when it goes out of scope and to not show when needed.
- Changing
mySecondForm.ShowDialog
toApplication2.ShowDialog(mySecondForm)
.
- This causes the main menu on
mySecondForm
to not work (clicking has no effect, just beeps).
- This causes the main menu on
- Changing
mySecondForm.ShowDialog
toApplication2.ShowDialog(mySecondForm, true)
(true = clean up the dialog box).
- This this does not work because I need access to the dialog box after it closes some times.
Ideally I would like a way to attach a form to the message abilities of Application2.
But I welcome any suggestions.
Edit: Based on the suggestion for ctacke this is what I have done:
public static DialogResult ShowDialog2(this Form form)
{
//form.Activated += InsertMenu;
//Application2.ShowDialog(form);
form.Show();
try
{
do
{
Application2.DoEvents();
} while (form.Visible);
}
catch (ObjectDisposedException)
{
// This just means that the form was closed. Not a big deal.
}
return form.DialogResult;
}
I end up calling ShowDialog2 rather than ShowDialog