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.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Threading;

namespace TreeView
{
	/// <summary>
	/// Summary description for SdeTabPage.
	/// </summary>
	public class SdeTabPage : System.Windows.Forms.UserControl
	{
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private string m_image = null;
		private string m_text  = null;
		private bool m_selected = false;

		public bool IsSelected
		{
			get
			{
				return m_selected;
			}
			set
			{
				m_selected = value;
			}

		}
	
		private SdeTabPage()
		{
		}

		public SdeTabPage( string image, string text )
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();
			m_image = image;
			m_text = text;
			this.MouseEnter += new System.EventHandler(Ctrl_OnMouseEnter);
			this.MouseHover += new System.EventHandler(On_MouseHover);
			this.MouseLeave += new System.EventHandler(onMouseLeave);
			// TODO: Add any initialization after the InitForm call

		}

		protected override void OnPaint(PaintEventArgs pe)
		{
			base.OnPaint(pe);
			DrawSideStrips();
		}


		public  void DrawSideStrips()
		{
			Graphics g = this.CreateGraphics();
			g.Clear(this.BackColor);
			Image sampleImage = (Image) Resources.GetBitmap(m_image);

			if (IsSelected)
			{
				//g.DrawLine(new Pen(SystemBrushes.ControlDark), 0,30,25,30);
				//g.FillRectangle(SystemBrushes.ControlLight,2,2,this.Width-4,this.Height-4);
				g.DrawString(m_text,new Font("Arial",8.0f),SystemBrushes.ControlDarkDark,5,25,new StringFormat(StringFormatFlags.DirectionVertical));
				this.Height = 120;
			}
			else
			{
				this.Height = 21; 
			}
			g.DrawImage(sampleImage,5,3);
			ControlPaint.DrawBorder3D(g,0,0,this.Width,this.Height,Border3DStyle.Flat);
		}

		public  void Ctrl_OnMouseEnter(object sender,EventArgs args)
		{

				this.IsSelected = true;
				Point locate = new Point(2,2);
				foreach ( Control ctrl in this.Parent.Controls )
				{
					SdeTabPage temp = (SdeTabPage)ctrl;
					if ( this != temp )
					{
						temp.IsSelected = false;
					}
					ctrl.Location = locate;
					temp.DrawSideStrips();
					locate.Y += ctrl.Height ;
					locate.Y -=1;
				//	ctrl.Invalidate();
					
				}

			
		}

		public void On_MouseHover(object sender, EventArgs args)
		{
			Form1 myform  = (Form1)Form1.ActiveForm;
			for(int i= 0; i<=150; i+=10)
			{
				Thread.Sleep(10);
				myform.panel1.AutoScroll = false;
				myform.panel1.Width = i; 
					
			}	
			
		}
		
		private void onMouseLeave(object sender, System.EventArgs e)
		{
			Form1 myform  = (Form1)Form1.ActiveForm;
			
			Thread.Sleep(500);
			for(int i= 150; i>= 0; i-=10)
			{
				Thread.Sleep(10);
				myform.panel1.AutoScroll = false;
				myform.panel1.Width = i;
			}
		}

		/// <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 Component 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()
		{
			// 
			// SdeTabPage
			// 
			this.BackColor = System.Drawing.SystemColors.ControlLight;
			this.Name = "SdeTabPage";
			
			this.Size = new System.Drawing.Size(25, 120);
		}
		#endregion
	}
}

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 | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 26 Apr 2002
Article Copyright 2002 by helloravi
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid