C# 将每个窗体作为 MdiParent 的子项打开
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15762389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
open every Window form as child to MdiParent
提问by SML
I'm having MdiParent
form which has Menu
and Submenu
Parent Form is Say Form Aif I open Form Busing submenu option using following code
如果我使用以下代码使用子菜单选项打开表单 B,我有一个MdiParent
表单,Menu
并且Submenu
父表单是说表单 A
B addbill = new B();
B.Show();
B.MdiParent = this;
It opens Form Bas child of Form A. Now I want to open Form Cfrom Form Bafter click the Button on Form Band Form Bwill be closed and Form Cwill be opened as Child of Form AAgain after click button on Form C, Form CWill be closed and Form Bwill be opened as Form A
它打开Form B作为Form A 的子级。现在我想在单击表单 B上的按钮后从表单 B打开表单 C,表单 B将被关闭,并且表单 C将 在单击表单 C上的按钮后再次作为表单 A 的子项打开,表单 C将被关闭并且表单 B将作为Form A打开
So what can I do to do same ?
那么我能做些什么呢?
回答by Kelmen
before B is closed:
在 B 关闭之前:
C.MdiParent = B.MdiParent; // which is pointing to A
回答by Technology Newest
In Form B button click where you are calling Form C, you have to assign the MdiParent of FormB to MdiParent of FormC which is FormA. After that you can close FormB.
在 Form B 按钮单击您调用 Form C 的位置,您必须将 FormB 的 MdiParent 分配给 FormC 的 MdiParent,即 FormA。之后,您可以关闭 FormB。
//FormB Button Click
//FormB按钮点击
private void button1_Click(object sender, EventArgs e)
{
FormC frm = new FormC();
frm.MdiParent = this.MdiParent; // assign MdiParent of FormB to FormC
frm.Show();
this.Close();
}
回答by Anamika Sharma
On FormB button click event write this code:
在 FormB 按钮单击事件上编写以下代码:
FormC fc=new FormC();
fc.MdiParent=this.MdiParent;
fc.Show();
And in FormC load event write this code:
并在 FormC 加载事件中编写以下代码:
FormB fb=new FormB();
fb.Hide();
fb.Close();
回答by user4422323
private void button1_Click(object sender, EventArgs e)
{
Analysis an = new Analysis();//on login click open anothe form on same perrent
an.MdiParent = this.MdiParent;
an.Show();
}
回答by Sagar Jadhav
It's Work..Try This Code
它的工作..试试这个代码
private void btCountSale_Click(object sender, EventArgs e)
{
bool exist = false;
foreach (Form f in Application.OpenForms)
{
if (f.Text == "Counter Sale")
{
exist = true;
f.BringToFront();
break;
}
}
if (exist == false)
{
frmCounterSale fm = new frmCounterSale();
fm.MdiParent = this.MdiParent;
fm.Show();
}
}
回答by Sagar Jadhav
It's Work..Try This Code
它的工作..试试这个代码
private void btCountSale_Click(object sender, EventArgs e)
{
bool exist = false;
foreach (Form f in Application.OpenForms)
{
if (f.Name== "frmCounterSale")
{
exist = true;
f.BringToFront();
break;
}
}
if (exist == false)
{
frmCounterSale fm = new frmCounterSale();
fm.MdiParent = this.MdiParent;
fm.Show();
}
}