Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Collapsible Splitter control in C#

, 26 Aug 2003
A Mozilla-style collapsing splitter control in C#
collapsiblesplitter.zip
collapsiblesplittercsharp.zip
CollapsibleSplitter
CollapsibleSplitterCSharp
CollapsibleSplitter.bmp
CollapsibleSplitter.csproj.user
CollapsibleSplitterTest
CollapsibleSplitterTest.csproj.user
App.ico
collapsiblesplitterdemo.zip
collapsiblesplitterv1.2_demo.zip
collapsiblesplitterv1.2_src.zip
collapsiblesplitter_demo.zip
collapsiblesplitter_src.zip
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace NJFLib
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.ToolBarButton toolBarButtonToggle1;
		private System.Windows.Forms.ToolBarButton toolBarButtonToggle2;
		private System.Windows.Forms.ImageList imageList2;
		private System.Windows.Forms.MainMenu mainMenu;
		private System.Windows.Forms.StatusBar statusBar;
		private System.Windows.Forms.ToolBar toolBar;
		private System.Windows.Forms.Panel panelTop;
		private NJFLib.Controls.CollapsibleSplitter splitterTop;
		private System.Windows.Forms.RichTextBox richTextBox;
		private NJFLib.Controls.CollapsibleSplitter splitterPanelRight;
		private System.Windows.Forms.Panel panelRight;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.RadioButton radioButton3;
		private System.Windows.Forms.RadioButton radioButton2;
		private System.Windows.Forms.RadioButton radioButton1;
		private NJFLib.Controls.CollapsibleSplitter splitterTreeView;
		private System.Windows.Forms.TreeView treeView;
		private System.Windows.Forms.Panel panelBottom;
		private NJFLib.Controls.CollapsibleSplitter splitterBottom;
		private System.ComponentModel.IContainer components;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.mainMenu = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.statusBar = new System.Windows.Forms.StatusBar();
			this.toolBar = new System.Windows.Forms.ToolBar();
			this.toolBarButtonToggle1 = new System.Windows.Forms.ToolBarButton();
			this.toolBarButtonToggle2 = new System.Windows.Forms.ToolBarButton();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.imageList2 = new System.Windows.Forms.ImageList(this.components);
			this.panelBottom = new System.Windows.Forms.Panel();
			this.splitterBottom = new NJFLib.Controls.CollapsibleSplitter();
			this.panelTop = new System.Windows.Forms.Panel();
			this.splitterTop = new NJFLib.Controls.CollapsibleSplitter();
			this.richTextBox = new System.Windows.Forms.RichTextBox();
			this.splitterPanelRight = new NJFLib.Controls.CollapsibleSplitter();
			this.panelRight = new System.Windows.Forms.Panel();
			this.button1 = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.radioButton3 = new System.Windows.Forms.RadioButton();
			this.radioButton2 = new System.Windows.Forms.RadioButton();
			this.radioButton1 = new System.Windows.Forms.RadioButton();
			this.splitterTreeView = new NJFLib.Controls.CollapsibleSplitter();
			this.treeView = new System.Windows.Forms.TreeView();
			this.panelRight.SuspendLayout();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// mainMenu
			// 
			this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.menuItem1});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem2});
			this.menuItem1.Text = "&File";
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 0;
			this.menuItem2.Text = "E&xit";
			this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
			// 
			// statusBar
			// 
			this.statusBar.Location = new System.Drawing.Point(0, 259);
			this.statusBar.Name = "statusBar";
			this.statusBar.ShowPanels = true;
			this.statusBar.Size = new System.Drawing.Size(520, 22);
			this.statusBar.TabIndex = 0;
			this.statusBar.Text = "statusBar1";
			// 
			// toolBar
			// 
			this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																					   this.toolBarButtonToggle1,
																					   this.toolBarButtonToggle2});
			this.toolBar.DropDownArrows = true;
			this.toolBar.ImageList = this.imageList1;
			this.toolBar.Name = "toolBar";
			this.toolBar.ShowToolTips = true;
			this.toolBar.Size = new System.Drawing.Size(520, 33);
			this.toolBar.TabIndex = 1;
			this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);
			// 
			// toolBarButtonToggle1
			// 
			this.toolBarButtonToggle1.ImageIndex = 0;
			this.toolBarButtonToggle1.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton;
			this.toolBarButtonToggle1.ToolTipText = "Toggle the first CollapsibleSplitter";
			// 
			// toolBarButtonToggle2
			// 
			this.toolBarButtonToggle2.ImageIndex = 0;
			this.toolBarButtonToggle2.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton;
			this.toolBarButtonToggle2.ToolTipText = "Toggle the second CollapsibleSplitter";
			// 
			// imageList1
			// 
			this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.imageList1.ImageSize = new System.Drawing.Size(24, 24);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// imageList2
			// 
			this.imageList2.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.imageList2.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList2.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList2.ImageStream")));
			this.imageList2.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// panelBottom
			// 
			this.panelBottom.BackColor = System.Drawing.SystemColors.AppWorkspace;
			this.panelBottom.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.panelBottom.Location = new System.Drawing.Point(0, 163);
			this.panelBottom.Name = "panelBottom";
			this.panelBottom.Size = new System.Drawing.Size(520, 96);
			this.panelBottom.TabIndex = 2;
			this.panelBottom.Visible = false;
			// 
			// splitterBottom
			// 
			this.splitterBottom.AnimationDelay = 20;
			this.splitterBottom.AnimationStep = 20;
			this.splitterBottom.BorderStyle3D = System.Windows.Forms.Border3DStyle.SunkenOuter;
			this.splitterBottom.ControlToHide = this.panelBottom;
			this.splitterBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.splitterBottom.ExpandParentForm = true;
			this.splitterBottom.Location = new System.Drawing.Point(0, 155);
			this.splitterBottom.Name = "splitterBottom";
			this.splitterBottom.TabIndex = 3;
			this.splitterBottom.TabStop = false;
			this.splitterBottom.UseAnimations = true;
			this.splitterBottom.VisualStyle = NJFLib.Controls.VisualStyles.Lines;
			// 
			// panelTop
			// 
			this.panelTop.BackColor = System.Drawing.SystemColors.AppWorkspace;
			this.panelTop.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panelTop.Dock = System.Windows.Forms.DockStyle.Top;
			this.panelTop.Location = new System.Drawing.Point(0, 33);
			this.panelTop.Name = "panelTop";
			this.panelTop.Size = new System.Drawing.Size(520, 39);
			this.panelTop.TabIndex = 4;
			// 
			// splitterTop
			// 
			this.splitterTop.AnimationDelay = 20;
			this.splitterTop.AnimationStep = 20;
			this.splitterTop.BorderStyle3D = System.Windows.Forms.Border3DStyle.Flat;
			this.splitterTop.ControlToHide = this.panelTop;
			this.splitterTop.Dock = System.Windows.Forms.DockStyle.Top;
			this.splitterTop.ExpandParentForm = false;
			this.splitterTop.Location = new System.Drawing.Point(0, 72);
			this.splitterTop.Name = "splitterTop";
			this.splitterTop.TabIndex = 5;
			this.splitterTop.TabStop = false;
			this.splitterTop.UseAnimations = false;
			this.splitterTop.VisualStyle = NJFLib.Controls.VisualStyles.Mozilla;
			// 
			// richTextBox
			// 
			this.richTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
			this.richTextBox.Location = new System.Drawing.Point(168, 80);
			this.richTextBox.Name = "richTextBox";
			this.richTextBox.Size = new System.Drawing.Size(192, 75);
			this.richTextBox.TabIndex = 21;
			this.richTextBox.Text = "Collapsible Splitter Control by Furty";
			// 
			// splitterPanelRight
			// 
			this.splitterPanelRight.AnimationDelay = 20;
			this.splitterPanelRight.AnimationStep = 20;
			this.splitterPanelRight.BorderStyle3D = System.Windows.Forms.Border3DStyle.Flat;
			this.splitterPanelRight.ControlToHide = this.panelRight;
			this.splitterPanelRight.Dock = System.Windows.Forms.DockStyle.Right;
			this.splitterPanelRight.ExpandParentForm = true;
			this.splitterPanelRight.Location = new System.Drawing.Point(360, 80);
			this.splitterPanelRight.Name = "splitterPanelRight";
			this.splitterPanelRight.TabIndex = 20;
			this.splitterPanelRight.TabStop = false;
			this.splitterPanelRight.UseAnimations = false;
			this.splitterPanelRight.VisualStyle = NJFLib.Controls.VisualStyles.DoubleDots;
			// 
			// panelRight
			// 
			this.panelRight.BackColor = System.Drawing.SystemColors.Control;
			this.panelRight.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panelRight.Controls.AddRange(new System.Windows.Forms.Control[] {
																					 this.button1,
																					 this.groupBox1});
			this.panelRight.Dock = System.Windows.Forms.DockStyle.Right;
			this.panelRight.Location = new System.Drawing.Point(368, 80);
			this.panelRight.Name = "panelRight";
			this.panelRight.Size = new System.Drawing.Size(152, 75);
			this.panelRight.TabIndex = 19;
			// 
			// button1
			// 
			this.button1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.button1.Location = new System.Drawing.Point(8, 136);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(124, 23);
			this.button1.TabIndex = 2;
			this.button1.Text = "A Button";
			// 
			// groupBox1
			// 
			this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.radioButton3,
																					this.radioButton2,
																					this.radioButton1});
			this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(132, 120);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Some radio buttons";
			// 
			// radioButton3
			// 
			this.radioButton3.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.radioButton3.Location = new System.Drawing.Point(16, 88);
			this.radioButton3.Name = "radioButton3";
			this.radioButton3.TabIndex = 2;
			this.radioButton3.Text = "radioButton3";
			// 
			// radioButton2
			// 
			this.radioButton2.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.radioButton2.Location = new System.Drawing.Point(16, 56);
			this.radioButton2.Name = "radioButton2";
			this.radioButton2.TabIndex = 1;
			this.radioButton2.Text = "radioButton2";
			// 
			// radioButton1
			// 
			this.radioButton1.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.radioButton1.Location = new System.Drawing.Point(16, 24);
			this.radioButton1.Name = "radioButton1";
			this.radioButton1.TabIndex = 0;
			this.radioButton1.Text = "radioButton1";
			// 
			// splitterTreeView
			// 
			this.splitterTreeView.AnimationDelay = 20;
			this.splitterTreeView.AnimationStep = 20;
			this.splitterTreeView.BorderStyle3D = System.Windows.Forms.Border3DStyle.Flat;
			this.splitterTreeView.ControlToHide = this.treeView;
			this.splitterTreeView.ExpandParentForm = false;
			this.splitterTreeView.Location = new System.Drawing.Point(160, 80);
			this.splitterTreeView.Name = "splitterTreeView";
			this.splitterTreeView.TabIndex = 18;
			this.splitterTreeView.TabStop = false;
			this.splitterTreeView.UseAnimations = false;
			this.splitterTreeView.VisualStyle = NJFLib.Controls.VisualStyles.XP;
			// 
			// treeView
			// 
			this.treeView.Dock = System.Windows.Forms.DockStyle.Left;
			this.treeView.ImageList = this.imageList2;
			this.treeView.Location = new System.Drawing.Point(0, 80);
			this.treeView.Name = "treeView";
			this.treeView.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
																				 new System.Windows.Forms.TreeNode("Desktop", 0, 0, new System.Windows.Forms.TreeNode[] {
																																											new System.Windows.Forms.TreeNode("My Computer", 1, 1, new System.Windows.Forms.TreeNode[] {
																																																																		   new System.Windows.Forms.TreeNode("Floppy Drive (A:)", 2, 2),
																																																																		   new System.Windows.Forms.TreeNode("Hard Drive (C:)", 3, 3),
																																																																		   new System.Windows.Forms.TreeNode("DVD/CD-RW Drive (D:)", 4, 4),
																																																																		   new System.Windows.Forms.TreeNode("Shared Documents", 8, 8)}),
																																											new System.Windows.Forms.TreeNode("My Documents", 5, 5),
																																											new System.Windows.Forms.TreeNode("My Network Places", 6, 6),
																																											new System.Windows.Forms.TreeNode("Recycle Bin", 7, 7)})});
			this.treeView.Size = new System.Drawing.Size(160, 75);
			this.treeView.TabIndex = 17;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(520, 281);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.richTextBox,
																		  this.splitterPanelRight,
																		  this.panelRight,
																		  this.splitterTreeView,
																		  this.treeView,
																		  this.splitterTop,
																		  this.panelTop,
																		  this.splitterBottom,
																		  this.panelBottom,
																		  this.toolBar,
																		  this.statusBar});
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Menu = this.mainMenu;
			this.Name = "Form1";
			this.Text = "Collapsible Splitter Control for .NET";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.panelRight.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			this.treeView.Nodes[0].ExpandAll();
		}

		private void splitterTreeView_Click(object sender, System.EventArgs e)
		{
			this.toolBarButtonToggle1.Pushed = this.splitterTreeView.IsCollapsed;
		}

		private void splitterPanelRight_Click(object sender, System.EventArgs e)
		{
			this.toolBarButtonToggle2.Pushed = this.splitterPanelRight.IsCollapsed;
		}

		private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch(toolBar.Buttons.IndexOf(e.Button))
			{
				case 0:
					this.splitterTreeView.ToggleState();
					this.toolBarButtonToggle1.Pushed = this.splitterTreeView.IsCollapsed;
					break;
				case 1:
					this.splitterPanelRight.ToggleState();
					this.toolBarButtonToggle2.Pushed = this.splitterPanelRight.IsCollapsed;
					break;
			}

		}

		private void menuItem2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Furty
Web Developer
Thailand Thailand
Furty will code for food.

| Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 27 Aug 2003
Article Copyright 2002 by Furty
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid