无法使用 c# 将表单显示为 mdiChild 表单

Unable to show a form as a mdiChild form using c#

我正在构建一个 C#(VS 2015) 桌面应用程序。现在这个应用程序有几种形式,其中 'frmMain' 有 IsMdiContainer= true ,其余都是子形式。现在,在其中一个子表单 'frmChild1' 中,按钮单击事件下有以下代码。

if(chkMarksEntrdOrNot(tsDDBSession.ToString(), tsDDBClass.ToString()) == false)
{

}
else
{
   MessageBox.Show("Marks of all the applicants for the chosen Session and Class have not been entered yet. Please enter marks then come again to this menu.",Application.ProductName,MessageBoxButtons.OK);
   this.Close();
   Admission.frmAdmissionTestMarksEntryBrows fATMEB = new frmAdmissionTestMarksEntryBrows();
   //frmMain fMn = new frmMain();
   //fATMEB.MdiParent = fMn;
   fATMEB.Show();
}

从上面的代码可以看出,在其他部分,我正在关闭当前表单,然后尝试显示另一个子表单(frmAdmissionTestMarksEntryBrows)。该窗体正在显示,但不是作为 mdiChild 窗体。我想将其显示为 mdiChild 形式。我希望你理解我的 problem.Please 帮助。

//frmMain fMn = new frmMain();
//fATMEB.MdiParent = fMn;

您没有在显示之前设置窗体的 MdiParent。

您需要对主窗体的实际引用 frmMain(因为从上面的评论中,我们了解到 frmMain 是所需的父级),并且不应尝试创建新实例。

如果您尝试将此新表单作为 mdichild 添加到您自己的父级,请尝试:

fATMEB.MdiParent = this.MdiParent;

(关闭自己之前)