dotjoe
dotjoe

Reputation: 26940

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

Upvotes: 3

Views: 9646

Answers (3)

user3685581
user3685581

Reputation:

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!

Upvotes: 0

Chris Holmes
Chris Holmes

Reputation: 11574

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.

Upvotes: 3

Joey
Joey

Reputation: 2951

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

Upvotes: 4

Related Questions