I have a .net winforms application, where multiple forms are displayed at one time. One form is routinley disabled (this.enabled = false;). During this time, the form creates and shows a custom modal dialog. When the dialog is closed, the original form, the one that is disabled, loses focus. I removed the code that set the form as disabled, and when I tested that, the form kept the focus after returning from the dialog. Is there any way to have a disabled form open up a modal custom dialog, and then stay focused and on top of the other forms when the dialog is closed?
I have a .net winforms application, where multiple forms are displayed at one time.
Share
No. The Windows manager must pick another window to give the focus to when the dialog closes. When your app has no enabled windows left, it must pick a window of another application. Which is likely to push your app’s windows into the background.
A possible workaround is to quickly enable the window before the dialog closes and disable it again afterwards. Like this:
But do note that this is in general a usability problem. Once the user switches to another application, she can’t switch back to yours again.