在我的applcation中,我有4个窗体,form1是一个mdi容器,其余窗体是childs, 在form1中,我打开所有子窗体的加载事件。在子窗口2,我有一个按钮,就会切换到childform3.my问题是如何当你创建你的窗口2显示childform2如何显示(Bringtofront)已从另一个Mdi儿童窗体打开的Mdi儿童窗体?
form1:
Form2 formchild1;
Form3 formchild2;
Form4 formchild3;
private void Form1_Load(object sender, EventArgs e)
{
if (formchild2 == null)
{
formchild2 = new Form3();
}
formchild2.MdiParent = this;
formchild2.Dock = DockStyle.Fill;
formchild2.Show();
//formchild2.BringToFront();
if (formchild3 == null)
{
formchild3 = new Form4();
}
formchild3.MdiParent = this;
formchild3.Dock = DockStyle.Fill;
formchild3.Show();
if (formchild1 == null)
{
formchild1 = new Form2();
}
formchild1.MdiParent = this;
formchild1.Show();
formchild1.Dock = DockStyle.Fill;
formchild1.BringToFront();
}
form2:
Form3 formchild2;
private void button1_Click(object sender, EventArgs e)
{
//what i have to write hare..
//formchild2 = new Form3();
//formchild2.MdiParent = this.ParentForm;
//formchild2.Dock = DockStyle.Fill;
//formchild2.Show();
//formchild2.BringToFront();
}
如果我在按钮中初始化新实例,它将在每次点击按钮时创建新的窗体实例。 – user3413736 2014-09-04 07:48:16
让一个孩子知道另一个表单是一个非常容易的做法。将此代码放入MDI父窗体中,它必须已经知道您的所有子窗体。只需从孩子调用它,就像((MyMDIParent)this.MdiParent).FooBar()。 – 2014-09-04 09:49:53
我没有得到你的解释,请发送更多的代码,谢谢你 – user3413736 2014-09-04 12:16:50