Search code examples
.netwinformsmdishowdialog

How to correctly ShowDialog() from inside an MDIChild form?


I have an MDIChild form that needs to show a dialog. I'm currently doing it like this from inside the mdichild form...

f.ShowDialog(Me)

Should I be using f.ShowDialog(mdiparent)?

What is the difference when setting the owner before calling ShowDialog()?


Solution

  • The difference is in which parent owns the dialog. If you explicitly set the parent then that window owns the dialog. If you don't set it (using the parameterless version of ShowDialog) then the current active window of your application owns the dialog. That's on MSDN, btw.

    Where this is useful is in centering your dialog by setting the StartPosition property using the FormStartPosition.CenterParent enumeration.