My application's notification icon shows and hides the main application window accordingly. However, when a modal dialog is opened (this can be the About dialog or Settings dialog, to name a few) I want to the modal dialog to gain focus instead of showing/hiding the main application window.
The modal dialogs are opened with form.ShowDialog(this)
. Let's say I open the About window with that code and then, without closing it, I move to a different application. When I get back, if I click the notification icon, I want my application to get focus. Better yet, I want to the modal dialog to get focus cause since it's modal, I cannot use the parent form anyway.
I keep track with a simple bool
variable if any form (About, Settings, etc) is opened and when I click the notification icon I check for that variable. If it's true, I do something like mainForm.Activate()
. This actually brings the main form and the modal dialog to the front, the only problem is that it doesn't focus the modal dialog.
How can I solve this problem without keeping track of which modal dialog is opened and call .Activate()
on that? Cause that would be a pain...