Blue Theme Orange Theme Green Theme Red Theme
 
DevExpress Free UI Controls
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » Windows Controls C# » SplitContainer in C#

SplitContainer in C#

SplitContainer control provides functionality of a splitter to divide and resize two controls. In this article, we will discuss how to create and use a SplitContainer control in a Windows Forms application.

Author Rank :
Page Views : 7622
Downloads : 105
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
SplitContainerSampleCSharp.zip
 
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


SplitContainer control provides functionality of a splitter to divide and resize two controls. In this article, we will discuss how to create and use a SplitContainer control in a Windows Forms application.

Creating a SplitContainer

A SplitContainer has two built-in panels and a splitter. If you drag a SplitContainer control from Toolbox onto a Form, you will see output like Figure 1, where a splitter is separating Panel1 and Panel2 panels.

SplitContainerImg1.jpg 

Figure 1

Now if you can place any child controls in Panel1 and Panel2 and you will be able to resize them. Let's drag a TreeView control on Panel1 and ListBox control on Panel2 and set their Dock property to true. The output looks like Figure 2. If you run this application, you will see resizing option is available between TreeView and ListBox controls.

SplitContainerImg2.jpg

Figure 2

SplitContainer Properties

After you place a SplitContainer control on a Form, the next step is to set properties.

The easiest way to set properties is from the Properties Window. You can open Properties window by pressing F4 or right click on a control and select Properties menu item. The Properties window looks like Figure 3. You can also set properties of Panels by selecting a Panel and open the Properties window.

SplitContainerImg3.jpg

Figure 3

Orientation

Panels on a SplitContainer can be placed horizontally or vertically. The horizontal orientation places Panels like Figure 4. 

SplitContainerImg4.jpg

Figure 4

C# Code:

splitContainer1.Orientation = Orientation.Horizontal;

 

VB.NET Code:

 

splitContainer1.Orientation = Orientation.Horizontal

Panel1 and Panel2

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

C# Code:

SplitterPanel leftPanel = splitContainer1.Panel1;

leftPanel.BackColor = Color.Green;

leftPanel.ForeColor = Color.Yellow;           

 

SplitterPanel rightPanel = splitContainer1.Panel2;

rightPanel.BackColor = Color.OrangeRed;

rightPanel.ForeColor = Color.White;

 

VB.NET Code:

 

Dim leftPanel As SplitterPanel = SplitContainer1.Panel1

leftPanel.BackColor = Color.Green

leftPanel.ForeColor = Color.Yellow

 

Dim rightPanel As SplitterPanel = SplitContainer1.Panel2

rightPanel.BackColor = Color.OrangeRed

rightPanel.ForeColor = Color.White

Panel1Collapsed and Panel2Collapsed

Panel1Collapsed and Panel2Collapsed properties can be used to collapse and expand panels.

C# Code:

splitContainer1.Panel1Collapsed = true;

 

VB.NET Code:

 

splitContainer1.Panel1Collapsed = True

Panel1MinSize and Panel2MinSize

Panel1MinSize property gets or sets the minimum distance in pixels of the splitter from the left or top edge of Panel1. Panel2MinSize property gets or sets the minimum distance in pixels of the splitter from the right or bottom edge of Panel2.

C# Code:

splitContainer1.Panel1MinSize = 10;

splitContainer1.Panel2MinSize = 50;

 

VB.NET Code:

 

splitContainer1.Panel1MinSize = 10

splitContainer1.Panel2MinSize = 50

Splitter Properties

SplitterDistance property gets or sets the location of the splitter, in pixels, from the left or top edge of the SplitContainer.

SplitterIncrement property gets or sets a value representing the increment of splitter movement in pixels.

SplitterRectangle property gets the size and location of the splitter relative to the SplitContainer.

SplitterWidth property Gets or sets the width of the splitter in pixels.

C# Code:

splitContainer1.SplitterDistance = 50;

splitContainer1.SplitterIncrement = 10;

splitContainer1.SplitterWidth = 10;

 

VB.NET Code:

 

splitContainer1.SplitterDistance = 50

splitContainer1.SplitterIncrement = 10

splitContainer1.SplitterWidth = 10

 

Summary

In this article, we discussed discuss use a SplitContainer control and use its various properties.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Mahesh Chand
Mahesh is the founder of C# Corner and Mindcracker Network, an author of several .NET programming books and a Microsoft MVP for 6 consecutive years. In his day to day work, Mahesh is a Senior Software Consultant with over 14 years of IT industry experience building systems for Financial and Banking, Engineering & Architectural, Imaging, Construction, Biological & Pharmaceuticals, Healthcare and Education industries. His expertise is Windows Forms, ASP.NET, Silverlight, WPF, WCF, Visual Studio 2010, SQL Server, and Oracle.  If you are looking for a Sharepoint, Windows Forms, ASP.NET, WPF, Silverlight, C#, VB.NET, Oracle, and SQL Server Consultant in Philadelphia area or remote location, drop me a line at MAHESH [AT] C-SHARPCORNER [DOT] COM.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Chart
Become a Sponsor
 Comments
Post comment or questions by Mahesh On August 17, 2010
Post your comments or questions here
Reply | Email | Modify 
Thanks! by Jean Simon On August 17, 2010
Great article! Good job ;).
Reply | Email | Modify 
Nevron Chart
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.