Thursday 8 November 2012

How to add the Multiple SplitContainers in a Single form

Basically the SplitContainer devides the form Two Separate Panels,Some times we need to add the One more SplitContainer control to existed Panels  of SplitContainer1 ,as well as multliple SplitContainers.Here problem is Showing the Childforms.Why because?The Adding of the panels and show the ChildForm in  the Last Added SplitContainer Panel.

shown Below figure:


In SplitContainer Major Property is Orientation

Orientation:It is nothing but Placing the SplitContainer Horizantally (or) Vertically shown above figure.

For Example let us Discuss about above figure

In the figure SplitContainer1 it's Pane2 having the SplitContainer2 In Horizantal Orientation and also SplitContainer2 having two Panels Panel1(Pink color),Panel2(Light blue color)
Aftet that our task is showing  the ChildForm in the SplitContaner2-Panel2.For that first we have to add the SplitContainers by coding.

CodeSnippet:

     private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {
         SplitContainer1.Panel2.Controls.Add(SplitContainer2);
         }

  Note:  Above code the SplitContainer2 is added to SplitContainer1-panel2


private void SplitContainer2 _Panel2_Paint(object sender, PaintEventArgs e)
        {
           SplitContainer2.Panel2.Controls.Add(SplitContainer3);
        }

  Note:  Above code the SplitContainer3 is added to SplitContainer2-panel2       

In the Below code we showing how display the ChildForm in the middle of the form
 OrganizationPrflFrm frm = new OrganizationPrflFrm();    //creating the object for OrganizationPrflFrm
 frm.MdiParent = this;
 frm.Left = (this.spltcntnr3MdiFrm.Width - frm.Width) / 2;        //setting the width for the ChildForm
 frm.Top = (this.spltcntnr3MdiFrm.Height - frm.Height) / 2;    //setting the Height for the ChildForm
 spltcntnr3MdiFrm.Panel1.Controls.Add(frm);    //adding the form to SplitContainer3-panel1
 frm.Show();                                                    //Showing the ChildForm

Get More Details