articles

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

SplitContainer Control in C#.Net

SplitContainer Control in C#.Net

John Smith 18523 24-Jan-2011

A SplitContainer has two panels. The first panel is represented by Panel1 and the 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 the toolbox on the window Form.

SplitContainer Control in C#.Net

You can use both panels 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 panels 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 the application run.

Output

Panel1 is collapse.

SplitContainer Control in C#.Net


c# c# 
Updated 05-Jul-2020
I am best.

Leave Comment

Comments

Liked By