<bdo id='iK1zF'></bdo><ul id='iK1zF'></ul>

    1. <tfoot id='iK1zF'></tfoot>
    2. <legend id='iK1zF'><style id='iK1zF'><dir id='iK1zF'><q id='iK1zF'></q></dir></style></legend>
    3. <i id='iK1zF'><tr id='iK1zF'><dt id='iK1zF'><q id='iK1zF'><span id='iK1zF'><b id='iK1zF'><form id='iK1zF'><ins id='iK1zF'></ins><ul id='iK1zF'></ul><sub id='iK1zF'></sub></form><legend id='iK1zF'></legend><bdo id='iK1zF'><pre id='iK1zF'><center id='iK1zF'></center></pre></bdo></b><th id='iK1zF'></th></span></q></dt></tr></i><div id='iK1zF'><tfoot id='iK1zF'></tfoot><dl id='iK1zF'><fieldset id='iK1zF'></fieldset></dl></div>
    4. <small id='iK1zF'></small><noframes id='iK1zF'>

      .Owner 属性和 ShowDialog(IWin32Window 所有者)之间的区别?

      时间:2023-10-06
      <i id='x20F4'><tr id='x20F4'><dt id='x20F4'><q id='x20F4'><span id='x20F4'><b id='x20F4'><form id='x20F4'><ins id='x20F4'></ins><ul id='x20F4'></ul><sub id='x20F4'></sub></form><legend id='x20F4'></legend><bdo id='x20F4'><pre id='x20F4'><center id='x20F4'></center></pre></bdo></b><th id='x20F4'></th></span></q></dt></tr></i><div id='x20F4'><tfoot id='x20F4'></tfoot><dl id='x20F4'><fieldset id='x20F4'></fieldset></dl></div>
        <tbody id='x20F4'></tbody>

        • <bdo id='x20F4'></bdo><ul id='x20F4'></ul>

            <small id='x20F4'></small><noframes id='x20F4'>

          • <legend id='x20F4'><style id='x20F4'><dir id='x20F4'><q id='x20F4'></q></dir></style></legend>
                <tfoot id='x20F4'></tfoot>
                本文介绍了.Owner 属性和 ShowDialog(IWin32Window 所有者)之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我认为可以通过 .Owner 属性或通过在重载方法 ShowDialog(IWin32Window owner)

                I presume a winform's owner can be set explicitly via the .Owner property OR by passing the owner in the overloaded method ShowDialog(IWin32Window owner)

                我无法理解为什么这些方法在处理 MDI 表单时会表现出不同的行为.

                I am unable to understand why these methods exhibit different behavior when working with MDI forms.

                我创建了一个 MDIParent 和一个 MDIChild.

                I have created an MDIParent and an MDIChild.

                我还有一个简单的 winform MyDialogBox,它在加载时显示其所有者.

                I also have a simple winform MyDialogBox that displays its owner on load.

                MessageBox.Show("Dialog's owner is " + this.Owner.Name);
                

                方法 A - 在加载 MDIChild 我有以下代码,这导致 MyDialogBox 的所有者被设置为 MDIChild

                Method A - In the load of MDIChild I have the following code, which causes the MyDialogBox's owner to be set to MDIChild

                MyDialogBox box = new MyDialogBox();
                box.Owner = this; // Set owner as MDIChild
                box.ShowDialog();
                

                方法 B - 或者,在 MDIChild 的加载方法中,我有以下代码,这导致 MyDialogBox 的所有者被设置为 MDIParent

                Method B - Alternatively, in the load method of MDIChild I have the following code, which causes the MyDialogBox's owner to be set to MDIParent

                MyDialogBox box = new MyDialogBox();
                box.ShowDialog(this); // Pass MyMDIChild as owner
                

                我还阅读了以下这里

                只有 MDI 父窗体可以拥有另一个窗体,无论是 MDI 子窗体、模式对话框还是父窗体设置为所有者参数的窗体.

                如果是这样,方法 A 根本不应该工作,不是吗?

                If so Method A should not work at all, isn't it ?

                我错过了什么?为什么方法 B 不将所有者设置为 MDIChild ?

                What am I missing? Why doesn't method B set the owner to MDIChild ?

                推荐答案

                看这2个选项使用Reflector的区别,似乎它们的实现略有不同:box.Owner = this 只需将提供的 this 值分配给内部所有者字段.但是,当调用 ShowDialog(IWin32Window) 时,实现会在分配值之前执行以下调用:

                Looking at the differences of these 2 options using Reflector, it seems that they have a slightly different implementation: box.Owner = this just assign the provided value of this to the internal owner field. However, when calling ShowDialog(IWin32Window), the implementation performs the following call, prior to assigning the value:

                owner = ((Control) owner).TopLevelControlInternal;
                

                这可能会导致分配 MDIParent.

                This might result in assignment of the MDIParent.

                (注意:我远不是 MDI 方面的专家,所以我在这里可能错了).

                (Note: I'm far from being an expert regarding MDI, so I might be wrong here).

                这篇关于.Owner 属性和 ShowDialog(IWin32Window 所有者)之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:C#WPF)如何在showdialog()显示子模式窗口后最小化父窗口? 下一篇:无法在 WPF 中设置 DialogResult

                相关文章

                <legend id='niyFW'><style id='niyFW'><dir id='niyFW'><q id='niyFW'></q></dir></style></legend>

                <small id='niyFW'></small><noframes id='niyFW'>

                <i id='niyFW'><tr id='niyFW'><dt id='niyFW'><q id='niyFW'><span id='niyFW'><b id='niyFW'><form id='niyFW'><ins id='niyFW'></ins><ul id='niyFW'></ul><sub id='niyFW'></sub></form><legend id='niyFW'></legend><bdo id='niyFW'><pre id='niyFW'><center id='niyFW'></center></pre></bdo></b><th id='niyFW'></th></span></q></dt></tr></i><div id='niyFW'><tfoot id='niyFW'></tfoot><dl id='niyFW'><fieldset id='niyFW'></fieldset></dl></div>
                  • <bdo id='niyFW'></bdo><ul id='niyFW'></ul>

                  1. <tfoot id='niyFW'></tfoot>