简体   繁体   English

C#-从另一个MDI子窗体的按钮打开MDI子窗体

[英]C# - Opening mdi child form from another mdi child form's button

Can I actually open another mdi child form using the first mdi child form's button? 我实际上可以使用第一个MDI子窗体的按钮打开另一个MDI子窗体吗?

// Form1 is MdiParent
// Form2 is MdiChild1
// Form3 is MdiChild2

// Form2's code

private void button1_Click(Object sender, EventArgs e)
{
    Form1 parentForm = new Form1();
    Form3 childForm2 = new Form3();
    childForm2.MdiParent = parentForm;
    childForm2.Show();
}

My problem is when I clicked the button, it didn't showed up 我的问题是当我单击按钮时,它没有显示

It's appens because you are not showing the Form1 . 这是因为您没有显示Form1 If you want show mdi child form do this: 如果要显示mdi子窗体,请执行以下操作:

Form1 parentForm = new Form1();
Form3 childForm2 = new Form3();
childForm2.MdiParent = parentForm;
parentForm.Show();
childForm2.Show();

If Form1 is your current form and you want display the mdi child form into this form do this: 如果Form1是您当前的表单,并且要将mdi子表单显示在此表单中,请执行以下操作:

Form3 childForm2 = new Form3();
childForm2.MdiParent = this;
childForm2.Show();

PS I suggest you to don't use the default name because if you will have much usercontrol it will be mad to discover the correct control PS我建议你不要使用缺省的名字,因为如果你有多少用户控件这将是疯狂地发现正确的控制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM