Thursday 8 November 2012

How to use SplitContainer inWindows forms C#.net application

SplitContainer:SplitContainer is control,which is nothing but Movable bar that Devides a container's display area into two resizeble panels.

It splits the layout of your Windows Forms window into two parts: a left and right half, or a top and bottom half. It gives the user more control over how the window is arranged.
See below figure Panel1 and Panel2:


for example our windows  explorer it is also having SplitContaner with two panels one is left hand side that is our folder search,another one is whatever unformation is displayed in the right hand side while clicking on left side folderimages.

Panel1, Panel2
You can add or remove controls, or change existing controls, by using the Panel1 and Panel2 properties in C# code. In this example, we enumerate all the controls in Panel1 and Panel2 for the program shown in the screenshots above. The results indicate that a Button instance is found in Panel1 and a TextBox instance is found in Panel2.

Exaple Code Snippet:

using System;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        // Get information about Panel1 controls and Panel2 controls.
        StringBuilder builder = new StringBuilder();
        foreach (var control in splitContainer1.Panel1.Controls)
        {
        builder.Append("Panel1: ").AppendLine(control.GetType().ToString());
        }
        foreach (var control in splitContainer1.Panel2.Controls)
        {
        builder.Append("Panel2: ").AppendLine(control.GetType().ToString());
        }
        MessageBox.Show(builder.ToString());
    }
    }
}
Result:
Panel1: System.Windows.Forms.Button
Panel2: System.Windows.Forms.TextBox

For More Details