WinForms modal windows alt + tab problem

Suppose several Modal Windows are shown one above the other. They all have ShowInTaskbar = false, which means that TaskBaryou only see in MainForm, and all modal windows are hidden.

Now you press ALT + TAB , and the topmost modal Windows OSs disappear. But you cannot bring it back.

How should this be done correctly in your opinion?

+3
source share
2 answers

If a modal window gets stuck behind the main form, it looks like you are not setting its owner. When you call showDialog(), you need to pass the main form as follows:

modalWin.showDialog(mainForm);

Each time you call showDialog(), and your program has a different form, which should be at the bottom, it is better to transfer it as the owner. If you show a modal window when there is already a modal window up, then pass the first modal window as the owner.

+7
source

OK Just to complete:

Here's how to set the owner in Winform for Winform:

form.ShowDialog(ownerInstance);

Here's how to set the owner as Winform for a WPF window:

MyWpfDialog dialog = new MyWpfDialog();
new System.Windows.Interop.WindowInteropHelper(dialog).Owner = ownerInstance.Handle;
dialog.ShowDialog();

Here's how to set the owner in a Wpf window for a Wpf window:

.Owner = Window.GetWindow(ownerInstance)
0
source

Source: https://habr.com/ru/post/1741402/


All Articles