您首先通过将 ChildForm1 的引用传递给 ChildForm2 从 ChildForm1 打开 ChildForm2
ChildForm2 objChildForm2 = new ChildForm2(this);
objChildForm2.MdiParent = this.MdiParent;
objChildForm2.Show();
现在转到您的 ChildForm2 并添加参数化构造函数,同时创建 ChildForm1 的全局对象
ChildForm1 objChildForm1 = null;
public ChildForm2(ChildForm1 obj)
{
InitializeComponent();
objChildForm1 = obj; // Passing refrence of ChildForm1
obj.Hide(); // this will hide the ChildForm1
}
现在,当您的 ChildForm2 打开时,将调用上述参数化构造函数,它将隐藏您的 ChildForm1。您也可以在 ChildForm2 关闭时重新打开您的 ChildForm1。为此编写以下代码。
private void btnClose_Click(object sender, EventArgs e)
{
objChildForm1.Show();// you can access all public members of ChildForm1 by the Global //object "objChildForm1"
this.Close();
}