Home > DeveloperSection > Articles > SplitContainer Control in C#.Net

SplitContainer Control in C#.Net


C# C# 
Ratings:
0 Comment(s)
 10661  View(s)
Rate this:

SplitContainer Control in C#.Net

A SplitContainer has two panels. The first panel is represented by Panel1 and second panel is represented by Panel2. These panels can have their own properties and events.

How to use SplitContainer Control

Drag and drop SplitContainer control from toolbox on the window Form.

SplitContainer Control in C#.Net

You can use both panel as a separate panel.

Properties of SplitContainer control:

 

·         Orientation - Gets or sets a value indicating the Horizontal or Vertical orientation of the SplitContainer panels.

·         BackgroundImage- Instead of a single color, an image can be displayed as the background. The image only appears in the splitter bar.

Change color of Panel in SplitContainer

Code:

private void frmSplitContainer_Load(object sender, EventArgs e)

{

            //change the color of panel1

            splitContainer1.Panel1.BackColor = Color.Blue;

            //change the color of panel2

            splitContainer1.Panel2.BackColor = Color.DarkOliveGreen;

 }

Run the project

Backcolor of both panel in splitcontainer is different because both panel works as a separate panel in splitcontainer control.

SplitContainer Control in C#.Net

Collapse  panel in splitcontainer

You can collapse one panel out of two panels in SplitContainer.

Write the Code for collapse the Panel1 on form load

Example:

private void frmSplitContainer_Load(object sender, EventArgs e)

{

            // Panel1 will be collapse at run time

            splitContainer1.Panel1Collapsed = true;

 }

Panel1 will be collapse when application run.

Output

Panel1 is collapse.

SplitContainer Control in C#.Net


Don't want to miss updates? Please click the below button!

Follow MindStick