In my applcation i have 4 forms ,form1 is a mdi container and remaining forms are it childs, in form1 i am opening all child form in its load event. in child form2 i have a button which will switch to childform3.my problem is how to show childform3(which is already opened) from button in childform2
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();
}
When you create your form2 (Please change your variable names, it took a while to figure out that formchild1 was actually form2), you need to instantiate the form2 instance
if (formchild1 == null)
{
formchild1 = new Form2(/*Either pass in a Form3 here*/);
}
formchild1.formChild2 = formchild2; //Or make formChild2 public member
formchlid1.SetForm(formChild2); //Or make a method that sets it
formchild1.MdiParent = this;
formchild1.Show();
formchild1.Dock = DockStyle.Fill;
formchild1.BringToFront();
Then to show it again you can just do
formchild2.BringToFront();
childform3 childform3=new childform3;
private void button1_Click(object sender, EventArgs e)
{
if (!childform3.IsDisposed)
childform3.Select();
else
childform3= new frmSearch();
childform3.MdiParent = ParentForm;
childform3.Show();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.