1.I have 3 forms into my project mainform(MdiParent),child1 and child2.
2.Inside mainform contains two controls panel1,toolstrip1 and inside toolstrip1 control I added two Items toolstripbutton1,toolstripbutton2.
3.Child1 contains button1 control.
4. If mainform (MdiParent's) form's toolstripbutton1 click event I enter following code.
private void toolStripButton1_Click(object sender, EventArgs e)
{
toolStripButton1.Enabled = false;
child2 fr2 = new child2();
if (panel1.Controls.Count > 0)
{
foreach (Form afrm in this.panel1.Controls)
{
afrm.Close();
}
}
fr2.MdiParent = this;
this.panel1.Controls.Add(fr2);
fr2.Show();
fr2.FormClosed += (sen, eventarg) => { toolStripButton1.Enabled = true; };
}
Question : From above mentioned situation I have three questions -
If I click child1 forms button1 then I want to open child2 form inside Mdiparent form's panel1 control. How can I do this? How can I access MdiParent panel1 control from child1 form's button click event? Can I directly call above specified event from child1 button click?
Loading

VulpesPosted Jul 19, 2012, 12:13 PM
Also, if a form is opened within a panel, then it can no longer be an MDI child of the containing form which is why the MdiParent property of child2 is null even though you've tried to set it to mainform.
If you want to open child3 within the panel on mainform, then you'll have to forget about it being an MDI child, change the Modifiers property of panel1 from private to internal and use code such as this instead:
kishor chourePosted Jul 19, 2012, 12:38 PM
Thank you sir it's very useful to me.
kishor chourePosted Jul 19, 2012, 10:52 AM
VulpesPosted Jul 19, 2012, 10:19 AM
If you want to open child2 in panel1 on mainform, then you'll need to set the IsMdiContainer property to false and then change the code to open child2 to the following:
kishor chourePosted Jul 19, 2012, 9:55 AM
When I add panel1 inside mdiparent and open child2 inside it after button1_click of child2 form
child3 form will open but not within mdiparent container.
If I remove panel1 from mdiparent same code inside button1_click of child2 form will open the child3 inside mdiparent container.
try this and help me to open the child3 form inside mdiparent's panel1 control after click of button1 of child2.
VulpesPosted Jul 19, 2012, 9:28 AM
I assume you must have set mainform's IsMdiContainer property to true, otherwise you'd get an exception.
As this.MdiParent is evidently null, the only other thing I can suggest is to try and get a reference to mainform using other means.
Try this instead:
kishor chourePosted Jul 19, 2012, 12:58 AM
event as
private void toostripbutton1_click()
{
child2 c=new child2();
c.mdiparnet=this;
c.show();
}
but when I tried to open child3 form inside mdiparent from child2 form's button click event
as
class child2
{
private void button1_click()
{
child3 cf3=new child3();
cf3.Mdiparent=(Mainform)this.Mdiparent;
cf3.show();
}
}
from above code it opens my child3 form but not within the mainform (mdiparent) container. please help me.
VulpesPosted Jul 18, 2012, 1:48 PM
kishor chourePosted Jul 18, 2012, 1:07 PM
Another problem I am facing that I am unable to open my child3 form inside mdiparent form on button_click event on child2.
VulpesPosted Jul 18, 2012, 8:53 AM
On the face of it, it can't possibly be 'mf' because every MdiChild must have have an MdiParent.
Also I wouldn't have thought that it could be 'toolStripButton1' either if you've added this from the VS designer rather than dynamically in code.
kishor chourePosted Jul 18, 2012, 8:09 AM
"Object reference not set to an instance of an object". Tail me the second method to call the events of parent form from child form.
VulpesPosted Jul 16, 2012, 4:34 PM