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

.NET style Side Tab Control

, 25 Apr 2002
.NET Side Tab
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TreeView
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TreeView treeView1;
		private System.Windows.Forms.TreeNode mySelectedNode;
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuFile;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.Splitter splitter1;
		public Panel panel1;
		private TreeView.SideTab sideTab1;
		private SideTab sd;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
						
			this.Load += new System.EventHandler(this.onLoad);

			CustomListBox list = new CustomListBox();
			//Controls.Add(list);
			sd = new SideTab();
			sd.Width = 26;
						
			SdeTabPage sp = new SdeTabPage("File.NewIcon","Model Explorer");
			sp.Location = new Point(2,2);
			sp.IsSelected = false;
			sd.Controls.Add(sp);
			
			SdeTabPage sp1 = new SdeTabPage("Icons.Class","Property Sheet");
			sp1.Location = new Point(2,22);
			sp1.IsSelected=false;
			sd.Controls.Add(sp1);

			SdeTabPage sp2 = new SdeTabPage("File.OpenIcon","Transformation");
			sp2.Location = new Point(2,42);
			sp2.IsSelected=true;
			sd.Controls.Add(sp2);

			this.panel1 = new Panel();
			panel1.Dock = DockStyle.Right;
			
			InitializeComponent();
			panel1.Controls.Add(treeView1);
			treeView1.Dock= DockStyle.Fill;
			treeView1.Scrollable = false;
			this.Controls.Add(panel1);
	
			Controls.Add(sd);

	
	
				
			//
			// 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.splitter1 = new System.Windows.Forms.Splitter();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.treeView1 = new System.Windows.Forms.TreeView();
			this.menuFile = new System.Windows.Forms.MenuItem();
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.sideTab1 = new TreeView.SideTab();
			this.SuspendLayout();
			// 
			// splitter1
			// 
			this.splitter1.Dock = System.Windows.Forms.DockStyle.Right;
			this.splitter1.Location = new System.Drawing.Point(289, 0);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(3, 273);
			this.splitter1.TabIndex = 1;
			this.splitter1.TabStop = false;
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.Text = "Edit";
			this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
			// 
			// treeView1
			// 
			this.treeView1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.treeView1.FullRowSelect = true;
			this.treeView1.ImageIndex = -1;
			this.treeView1.Location = new System.Drawing.Point(171, 0);
			this.treeView1.Name = "treeView1";
			this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
																				  new System.Windows.Forms.TreeNode("Node0", new System.Windows.Forms.TreeNode[] {
																																									 new System.Windows.Forms.TreeNode("Node53")}),
																				  new System.Windows.Forms.TreeNode("Node21"),
																				  new System.Windows.Forms.TreeNode("Node22"),
																				  new System.Windows.Forms.TreeNode("Node23"),
																				  new System.Windows.Forms.TreeNode("Node24"),
																				  new System.Windows.Forms.TreeNode("Node25"),
																				  new System.Windows.Forms.TreeNode("Node26"),
																				  new System.Windows.Forms.TreeNode("Node27"),
																				  new System.Windows.Forms.TreeNode("Node28"),
																				  new System.Windows.Forms.TreeNode("Node29"),
																				  new System.Windows.Forms.TreeNode("Node30"),
																				  new System.Windows.Forms.TreeNode("Node31"),
																				  new System.Windows.Forms.TreeNode("Node32"),
																				  new System.Windows.Forms.TreeNode("Node33"),
																				  new System.Windows.Forms.TreeNode("Node34"),
																				  new System.Windows.Forms.TreeNode("Node35"),
																				  new System.Windows.Forms.TreeNode("Node36"),
																				  new System.Windows.Forms.TreeNode("Node37"),
																				  new System.Windows.Forms.TreeNode("Node38"),
																				  new System.Windows.Forms.TreeNode("Node39"),
																				  new System.Windows.Forms.TreeNode("Node40"),
																				  new System.Windows.Forms.TreeNode("Node41"),
																				  new System.Windows.Forms.TreeNode("Node42"),
																				  new System.Windows.Forms.TreeNode("Node43"),
																				  new System.Windows.Forms.TreeNode("Node44"),
																				  new System.Windows.Forms.TreeNode("Node45"),
																				  new System.Windows.Forms.TreeNode("Node46"),
																				  new System.Windows.Forms.TreeNode("Node47"),
																				  new System.Windows.Forms.TreeNode("Node48"),
																				  new System.Windows.Forms.TreeNode("Node49"),
																				  new System.Windows.Forms.TreeNode("Node50"),
																				  new System.Windows.Forms.TreeNode("Node51"),
																				  new System.Windows.Forms.TreeNode("Node52")});
			this.treeView1.SelectedImageIndex = -1;
			this.treeView1.Size = new System.Drawing.Size(121, 273);
			this.treeView1.TabIndex = 0;
			this.treeView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView1_MouseDown);
			this.treeView1.AfterLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.treeView1_AfterLabelEdit);
			// 
			// menuFile
			// 
			this.menuFile.Index = 0;
			this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.menuItem1});
			this.menuFile.Text = "File";
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuFile});
			// 
			// sideTab1
			// 
			this.sideTab1.BackColor = System.Drawing.Color.Blue;
			this.sideTab1.Dock = System.Windows.Forms.DockStyle.Right;
			this.sideTab1.Location = new System.Drawing.Point(273, 0);
			this.sideTab1.Name = "sideTab1";
			this.sideTab1.Size = new System.Drawing.Size(16, 273);
			this.sideTab1.TabIndex = 2;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  
																		  this.treeView1});
			this.Menu = this.mainMenu1;
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);
			sd.Dock = System.Windows.Forms.DockStyle.Right;

		}
		#endregion

		private void onLoad(object sender, System.EventArgs e)
		{
			panel1.Width=0;
		}

		private void treeView1_MouseDown(object sender, 
			System.Windows.Forms.MouseEventArgs e)
		{
			mySelectedNode = treeView1.GetNodeAt(e.X, e.Y);
			
		}

		private void menuItem1_Click(object sender, System.EventArgs e)
		{
			treeView1.RightToLeft = RightToLeft.Yes;
			
			if (mySelectedNode != null && mySelectedNode.Parent != null)
			{
				treeView1.SelectedNode = mySelectedNode;
				treeView1.LabelEdit = true;
				mySelectedNode.BeginEdit();
			}
			else
			{
				MessageBox.Show("No tree node selected or selected node is a root node.\n" + 
					"Editing of root nodes is not allowed.", "Invalid selection");
			}
		}

		private void treeView1_AfterLabelEdit(object sender, 
			System.Windows.Forms.NodeLabelEditEventArgs e)
		{
			if (e.Label != null)
			{
				if(e.Label.Length > 0)
				{
					if (e.Label.IndexOfAny(new char[]{'@', '.', ',', '!'}) == -1)
					{
						// Stop editing without cancelling the label change.
						e.Node.EndEdit(false);
					}
					else
					{
						/* Cancel the label edit action, inform the user and 
						   place the node in edit mode again. */
						e.CancelEdit = true;
						MessageBox.Show("Invalid tree node label.\n" + 
							"The invalid characters are: '@','.', ',', '!'", 
							"Node Label Edit");
						e.Node.BeginEdit();
					}
				}
				else
				{
					/* Cancel the label edit action, inform the user and 
					   place the node in edit mode again. */
					e.CancelEdit = true;
					MessageBox.Show("Invalid tree node label.\nThe label cannot be blank", 
						"Node Label Edit");
					e.Node.BeginEdit();
				}
				this.treeView1.LabelEdit = false;
			}
		}
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

helloravi
Web Developer
United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 26 Apr 2002
Article Copyright 2002 by helloravi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid