tags:

views:

32

answers:

2

I am using C# and WinForms to create UI of my application.

I have main window and dialog, which is shown modal to the main window. Dialog window is not shown in task bar. I go to another application and return back by clicking at the main window task bat icon. I can see locked main window but cannot see dialog unless I select it in Alt-Tab. This is confusing for an application user.

How can I ensure showing modal window in this situation? I can see similar but unfortunately unsolved question http://stackoverflow.com/questions/1158394/alttab-in-vista-activates-main-window-instead-of-previously-active-child-window which regards to Vista (and I have Windows 7).

A: 

It sounds like your dialog is not properly owned by the main window. Make sure you have assigned the main window to the dialog object's Owner property before showing the modal dialog.

dthorpe
A: 

This is probably because you don't use the ShowDialog(owner) overload. You should fret a little bit about the exact reason that ShowDialog() cannot find an owner by itself and picked the desktop window instead. It isn't healthy. I cannot guess why from your post. See what explicitly setting the owner buys you.

Oh, this will happen when the dialog runs on its own thread. In which case ShowDialog(owner) is going to bomb.

Hans Passant
Silly me! I was sure I added owner to ShowDialog just because right before I passed owner to a child dialog constructor (which uses owner for another purposes).
Alex