views:

177

answers:

2

Hi !

Suppose multiple Modal Windows shown above each other. All of those have ShowInTaskbar = false, which means that in the TaskBar you only see the MainForm and all Modal Windows are hidden.

Now you press ALT+ TAB and the most upper modal Windows disappears. But you cannot get it back in front.

How should be this done correctly in your opinion?

+2  A: 

If a modal window is getting stuck behind the main form, it sounds like you are not setting its owner. When you call showDialog(), you need to pass in the main form like this:

modalWin.showDialog(mainForm);

Any time you call showDialog(), and your program has another form that should be underneath, it is best to pass it as the owner. If you show modal window when there is already a modal window up, then pass the first modal window as the owner.

Jordan Miner
A: 

OK Just to complete it:

This is how to set an Owner to be a Winform for a Winform:

form.ShowDialog(ownerInstance);

This is how to set an Owner to be a Winform for a WPF Window:

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

This is how to set an Ownder to be a Wpf Window for a Wpf Window:

.Owner = Window.GetWindow(ownerInstance)
PaN1C_Showt1Me