如何引用Windows窗体的所有者?

Ske*_*lio 1 c# winforms

Visual Studio 2013,Visual C#,Windows窗体应用程序.

我对两个Form类感兴趣.该AfterTheGameForm.csTheGameForm.cs.

只有当用户点击第二个按钮时,第一个弹出窗口才会弹出.

AfterTheGameForm afterTheGameForm = new AfterTheGameForm();
afterTheGameForm.Show(this);
Run Code Online (Sandbox Code Playgroud)

所以很明显TheGameForm是AfterTheGameForm的所有者.这就是我的问题...... 在AfterTheGameForm类中, 我想引用Owner类以使用它的特定方法.我肯定知道所有者属于TheGameForm,我正在尝试施放:

TheGameForm gForm = (TheGameForm)this.Owner;
        if(gForm!=null){               
            MessageBox.Show(theGameForm.CheckedRadioButton);
        }
        else
        {
            MessageBox.Show("theGameForm==null");
        }
Run Code Online (Sandbox Code Playgroud)

我也试过这个演员:

TheGameForm gForm = this.Owner as TheGameForm;
Run Code Online (Sandbox Code Playgroud)

gForm对象为null!怎么可能?

Jer*_*gen 7

那可能是因为你在构造函数中访问它.在Owner被构造后设置.试试这个Load活动.