简体   繁体   English

如何从MDIChild表单内部正确显示ShowDialog()?

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

I have an MDIChild form that needs to show a dialog. 我有一个MDIChild表单,需要显示一个对话框。 I'm currently doing it like this from inside the mdichild form... 我目前正在从mdichild表单内部执行此操作...

f.ShowDialog(Me)

Should I be using f.ShowDialog(mdiparent) ? 我应该使用f.ShowDialog(mdiparent)吗?

What is the difference when setting the owner before calling ShowDialog() ? 在调用ShowDialog()之前设置所有者时有什么区别?

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: 我不确定这是否相关,但是在ShowDialog中传递拥有表单时遇到了一些问题,我通常这样做:

f.Owner = Me
f.ShowDialog()

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. 如果未设置(使用ShowDialog的无参数版本),则应用程序的当前活动窗口将拥有该对话框。 That's on MSDN , btw. 那是在MSDN上 ,顺便说一句。

Where this is useful is in centering your dialog by setting the StartPosition property using the FormStartPosition.CenterParent enumeration. 在此有用的地方是通过使用FormStartPosition.CenterParent枚举设置StartPosition属性来使对话框居中。

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. 我有一个MDI子对象,它调用ShowDialog(Me),并且在出现的对话框窗口中,Me.Owner引用了MDI容器,而不是MDI子对象。

Using Me.Owner.ActiveControl is a workaround, but using: 使用Me.Owner.ActiveControl是一种解决方法,但是使用:

       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. 在出现的对话框窗口中,Me.Owner现在确实引用了MDI子级。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM