kishor choure

kishor choure

  • NA
  • 87
  • 46.2k

Can we access MdiParent form controls,event from child form ?

Jul 16 2012 4:09 PM
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?

Answers (12)