.NET
  Home arrow .NET arrow Page 2 - The Why and How of the SplitContainer Cont...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

The Why and How of the SplitContainer Control
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 13
    2006-11-27

    Table of Contents:
  • The Why and How of the SplitContainer Control
  • The two orientations of SplitContainer Controls
  • Docking and Anchoring of Controls
  • Anchoring to prevent obscuring
  • Hide and reveal panels with nested SplitContainers
  • Events related to the SplitContainer Control

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Why and How of the SplitContainer Control - The two orientations of SplitContainer Controls


    (Page 2 of 6 )

    Depending on the orientation property there are two types, the vertical which is the default, and the horizontal. Create a new Windows Application from File-->New Project after choosing Visual Basic as the project type. You can pick the Windows Application from Visual Studio's installed templates. This adds a WindowsApplication1.vb which may be changed to something of your choice. In this article it is called Vertical.vb which adds the form Vertical to the project with a default size of 300 x 300.

    Now double click the SplitContainer control in the Toolbox. This adds the SplitContainer which appears as a divider of the vertical form by two panels, Panel1 and Panel2. Each of these Panels is accessed by prefixing the SplitContainer1. For example Panel1 will be SplitContainer1.Panel1. Each panel has default properties related to layout, appearance, behavior, data, and so forth.

    It is possible to view the form which you may see displayed after building the project and running it as shown. You will see a thin line dividing the form. When you place your mouse on the line you will see that you can drag it to either side by moving the mouse. Sometimes you will not see this splitter in the displayed form unless you search for it with your mouse.

    Accessing the properties of the SplitContainer Control

    To see how the properties relate, place the following code snippet into the form's load event. The With...End With block sets the various properties such as the minimum and maximum sizes of the panels; the back color of the panel; the size of the SplitContainer; and so on. Comments have been added to the appropriate lines which should make the meaning clear.

    You can also add other controls to the panels, since the main function of the panels is to support the controls placed on them, including another SplitContainer to further divide the design area, as we shall see later. In this code, a text box is added to Panel2 and a Button is added to Panel1 at run time. The messages will echo the size of the panels and the total size of the SplitContainer.

    Public Class Vertical
    Private Sub Vertical_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Me.Load
    Dim txtbox As New TextBox
    txtbox.Text = "The is Panel2"
    Dim btn As New Button
    btn.Text = "Panel1 button"
    btn.ForeColor = Color.Crimson
    With SplitContainer1 .Dock = System.Windows.Forms.DockStyle.Fill 
    .ForeColor = System.Drawing.Color.Bisque .Location =
    New System.Drawing.Point(0, 0) ' you cannot resize Panel1 to less than
    25 pixels
    .Panel1MinSize = 25 ' you cannot approach right edge less by
    less than 30
    .Panel2MinSize = 30 .Size =
    New System.Drawing.Size(292, 273) .SplitterDistance = 79
    ' This splitter moves in 10-pixel increments. .SplitterIncrement =
    10 .SplitterWidth = 5 ' first element that gets tabbed is the
    SplitContainer1
    .TabIndex = 0 ' make Panel1's backcolor as aquamarine
    .Panel1.BackColor = System.Drawing.Color.Aquamarine End With Debug.Print("Panel1 width: " & _ SplitContainer1.Panel1.Width & vbCrLf) Debug.Print("Panel2 width: " & _ SplitContainer1.Panel2.Width & vbCrLf) Debug.Print("Total width: " & _ SplitContainer1.Panel1.Width + _ SplitContainer1.Panel2.Width + _ SplitContainer1.SplitterWidth & vbCrLf) SplitContainer1.Panel2.Controls.Add(txtbox) SplitContainer1.Panel1.Controls.Add(btn) End Sub End Class

    When you run this code you will see the following displayed.

    The following result will be printed to the output screen.

    Panel1 width: 79
    Panel2 width: 208
    Total width: 292
    

    More .NET Articles
    More By Jayaram Krishnaswamy


       · This is a nice control to use in your navigation strategy. Also good for displaying...
       · With the splitter control it was possible to place controls like labels on...
     

    .NET ARTICLES

    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT