tags:

views:

1446

answers:

3

I have an issue where the parent form will minimize to the task tray (but I don't think it is loosing focus because the next form that shows, the Studio IDE, has focus ) when I close a dialog/form that was shown by calling ShowDialog(owner). The weird thing is that this doesn't happen every time. I don't see how the owner/parent parameter is getting cleared so I don't know why the parent would go away.

+1  A: 

I can reproduce it every time.

The bug is not in WinForms, but in the windows API (I can just as easily reproduce it with C code).

Avoid triple-nested dialogs, that seems to be the primary trigger.

You can also refocus the correct form in OnClose.

Joshua
Also avoid showing MDI parent dialogs from MDI children forms. And you can't refocus, because only the focused application can focus forms. If you try to focus before the close, there's a dialog open so you can't. If you try after the close, you've lost focus yourself and you'll fail silently.
configurator
Funny, my test said that in WM_CLOSE, set focus to another form in the same app always worked. The anti-focus is asynchronous and if you call DestroyWindow() immediately afterwords it gets eaten.
Joshua
A: 

Set the focus to the Mdiparent of the form just before calling the Close(). Works for me...

A: 

Hi,

I have the same issue, which has been plaguing me for weeks!

I have placed logging calls at every event I can think of in the parent and child to try to capture the instant the parent is minimised, but I don't believe that any form event is called when the issue occurs.

I find that it not only happens when the child is closed, but also when the child makes a webservice call to perform some function.

Also, I don't believe it is limited to the .ShowDialog(owner) method of showing the child, but also to the .Show() method. My forms are regular C# or VB forms (not MDI).

Any offers?

Stephen