Question

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()?

Was it helpful?

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.

OTHER TIPS

I'm not sure if this is related, but I've had some issues with passing the owning form in ShowDialog, I usually do this:

f.Owner = Me
f.ShowDialog()

It does make a difference...

I have an MDI child that calls ShowDialog(Me) and in the resulting dialog window, Me.Owner references the MDI container, not the MDI child.

Using Me.Owner.ActiveControl is a workaround, but using:

       Dim ContractForm As New Contract(strType, intMode)
       ContractForm.Owner = Me
       dgrAction = ContractForm.ShowDialog()

Gets it nicely. In the resulting dialog window, Me.Owner now does reference the MDI child.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top