Form.ShowDialog() overloads

F

Frank Rizzo

I am not grokking the difference between Form.ShowDialog() and
Form.ShowDialog(this). I have a form (parent form) that kicks off a
modal dialog using Form.ShowDialog(). The modal dialog has a 3rd party
control on it. The weird thing is that I can click on parent form's
icon in the taskbar and it will bring up the parent form (obscuring the
modal form). I can't do anything on the parent form (e.g. it does not
take mouse or keyboard input), so to users it looks hung.

If I only have native controls on the modal form, I do not see this
behavior (e.g. cannot bring up the parent form while the modal form is
showing).

The odd thing is that if I call the modal form using
Form.ShowDialog(this), the application behaves properly.

So it's probably something to do with the 3rd party control. Could it
be messing (is it even possible) with the ownership of the form?

Thanks.
 
P

Peter Duniho

[...]
So it's probably something to do with the 3rd party control. Could it
be messing (is it even possible) with the ownership of the form?

Yes. The parameterless ShowDialog() simply uses a "default" parent. When
you have the 3rd party control, this default parent is something other
than the parent form, causing the behavior you see.

For what it's worth, the default parent is whatever the "currently active
window" is. Obviously in the case of the 3rd party control, there's some
extra window running around that is treated as the "currently active
window". Assuming the 3rd party control is really just a control, this
seems wrong to me, but then there's lots of 3rd-party stuff out there
that's wrong.

Anyway, you found the appropriate work-around. When you care what the
parent is, you need to set it explicitly.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top