Click here to Skip to main content
13,795,616 members
Click here to Skip to main content
Add your own
alternative version


274 bookmarked
Posted 29 Sep 2002

Magic TabControl - VS.NET Style

, 29 Sep 2002
Rate this:
Please Sign up or sign in to vote.
An article on tab controls
<!-- Download Links --> <!-- Article image -->

Sample Image - MagicTabControl.gif

<!-- Add the rest of your HTML here -->

Why another TabControl?

The .NET Framework contains a wide range of user interface controls, but they offer only a basic look and feel. Today's user expects a richer experience that you just cannot build with the out-of-the-box controls. The Magic Library (of which this TabControl is a major part) aims to solve this by providing a set of user interface elements that add the sophistication expected from modern Windows applications.


The first download TabControl Sample contains a Form with a TabControl instance that allows the various properties of the TabControl to be experimented with. The source code for the actual control is inside the separate second download. At nearly 1MB in size, I thought people would prefer to download the sample before deciding if they want to install the entire source code project!

Class Crownwood.Magic.TabControl

The TabControl is used to manage a collection of TabPage instances which themselves are used to describe an individual page. Only a single page can be displayed at any time and a row of tabs are shown to allow the user to select between the available pages.

Creating tab pages in Visual Studio .NET

You can use the designer to modify a TabControl instance along with its TabPage instances. First you will need to add the control to the toolbox by right-clicking the toolbox window and selecting the customize option. Navigate to the appropriate directory and select the Magic Library DLL. The toolbox will now list the extra controls that are exposed by the library including the TabControl. Drag and drop a new instance onto your Form and select the TabPages property.

This will cause a dialog to appear that allows the creation and removal of pages to the control instance. It also allows you to modify the properties for each page added. Dismiss this dialog and you can now click on the control tabs in order to select the page you want to configure. As the TabPage class is derived from the Panel class you can now drag and drop other controls onto the page as desired. The designer will automatically generate the code needed to cause this configuration to be persisted as code in your Form.

The TabPages Collection

The TabControl exposes a property called TabPages that allows the developer to add, remove and modify pages displayed by the control. Use the standard methods to modify this collection as you would with any of the framework collections.

Here is an example that shows the collection being manipulated: -

Crownwood.Magic.Controls.TabControl tab =
       new Crownwood.Magic.Controls.TabControl();

Crownwood.Magic.Controls.TabPage tabPage1 =
          new Crownwood.Magic.Controls.TabPage();
Crownwood.Magic.Controls.TabPage tabPage2 =
          new Crownwood.Magic.Controls.TabPage();

// Add a range of pages to the collection
tab.TabPages.AddRange(new TabPage[] pages{
                            tabPage1, tabPage2});

// Remove all the contents

// Add a single entry

// Insert a single entry at a given position
tab.TabPages.Insert(0, tabPage2);

// Use index accessor for retrieving a page
// reference
Console.WriteLine("TabPages[0] name = {0}",

// Test if the collection contains an entry
Console.WriteLine("Contains tabPage1 = {0}",

// Gain access to a Page by its Title
Console.WriteLine("Contains a named page? {0}",
                  tab.TabPages["Page1"] != null);

// Remove by object reference

// Remove by index


The first property you should modify is the Appearance which, as the name suggests, is used to define the appearance of the control. When the value of this property is changed it will automatically alter the values of other properties to the defaults for the defined appearance. Therefore this is the first property to be set otherwise previous changes to other properties will be overwritten once this is set.

The three possible values for the property are VisualAppearance.MultiDocument, VisualAppearance.MultiForm and VisualAppearance.MultiBox. The first of these will place the page tabs at the top of the control and show both arrow and close buttons. An example use of this would be to control which of a group of documents is displayed. For example, use this appearance to achieve the same effect as the Visual Studio .NET control that contains the open documents.

The second appearance VisualAppearance.MultiForm places the page tabs at the bottom of the control and does not show any buttons. Instead all the tabs are sized to fit within whatever width the control is defined as. Use this appearance to mimic the style of tab control seen in Visual Studio .NET inside docking windows.

Use the third appearance VisualAppearance.MultiBox to create the high contrast appearance you get when editing an HTML document in Visual Studio .NET, where the document has two options at the bottom of the window.

Once the appearance has been set the developer can still modify the other properties to alter the exact look and feel wanted. For example, the PositionTop property could be used to shift the default position of the tabs for the MultiForm appearance from the bottom of the control to the top. Use the supplied sample project to experiment and achieve the look required.


There are several possible events that can be generated by the TabControl but only two are of interest to most developers. These are the ClosePressed event that gets fired when the user presses the close button, and SelectionChanged which notifies a change in the current selection.

To see how to hook into these events see the following code: -

public void SomeMethod()
   Crownwood.Magic.Controls.TabControl tab = 
       new Crownwood.Magic.Controls.TabControl();

   tab.ClosePressed += new EventHandler(
   tab.SelectionChanged += new EventHandler(


protected void OnClosePressed(object sender,
                                     EventArgs e)

protected void OnSelectionChanged(object sender,
                                     EventArgs e)
   Crownwood.Magic.Controls.TabControl tab = 
   Console.WriteLine("New selection = {0}",

Extra Features

Although you can use the control to achieve the same look and feel as the Visual Studio .NET TabControl, it also has a couple of extra goodies. You can use the Multiline property to get a multi lines display of tabs which you will not see in the VS.NET version. Another interesting feature is the HideTabsMode property. You can use this to decide when the tabs area is made visible/invisible. For example, you can have the tabs hidden unless the mouse is hovering over the control. Check out the sample to play around with this and the other available options.

Revision History

30 Sept 2002 - Initial Revision


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


About the Author

Phil Wright
Web Developer
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
zifeiwo6-Sep-13 18:50
memberzifeiwo6-Sep-13 18:50 
QuestionHow to call form_closing() event Pin
Somnath kadam16-Jan-13 22:42
memberSomnath kadam16-Jan-13 22:42 
QuestionHow to know if Tab Contains a page already of the name using VB.NET? Pin
wmason123429-Aug-12 6:06
memberwmason123429-Aug-12 6:06 
GeneralUse Crownwood tabcontrol in C# 2010 Pin
ajaxswan6-Jun-11 8:49
memberajaxswan6-Jun-11 8:49 
QuestionTabbed web browser Pin
Stenio Joseph9-Jan-11 4:12
memberStenio Joseph9-Jan-11 4:12 
GeneralMy vote of 1 Pin
karthikeyan198331-Aug-10 3:05
memberkarthikeyan198331-Aug-10 3:05 
GeneralRe: My vote of 1 Pin
Johnny J.28-Sep-10 23:14
professionalJohnny J.28-Sep-10 23:14 
GeneralCrownwood.Magic.Controls.TabControl does not dispose its child tab pages Pin
Meleagerster27-May-10 16:19
memberMeleagerster27-May-10 16:19 
QuestionUsage Pin
Aleksei Karimov14-Jan-08 8:24
memberAleksei Karimov14-Jan-08 8:24 
QuestionVisual Studio 2005? Pin
shubhabratam21-Oct-07 1:33
membershubhabratam21-Oct-07 1:33 
QuestionHow to add a minimize,maximize,restore button to tab control Pin
Iftekhar Naim14-Dec-06 5:54
memberIftekhar Naim14-Dec-06 5:54 
QuestiondataTableAdapter Pin
ppro7-Dec-06 15:49
memberppro7-Dec-06 15:49 
Generalhide an ordinary tab page Pin
Muammar©26-Nov-06 23:41
member Muammar©26-Nov-06 23:41 
GeneralRe: hide an ordinary tab page Pin
Ghazi H. Wadi24-Mar-07 3:04
memberGhazi H. Wadi24-Mar-07 3:04 
AnswerRe: hide an ordinary tab page Pin
Muhammad Adil31-Jul-08 21:49
memberMuhammad Adil31-Jul-08 21:49 
GeneralAwesome!! (NOT a sham) Pin
Skcheng17-Nov-06 19:49
memberSkcheng17-Nov-06 19:49 
GeneralExtending Into CAB Pin
PITRep16-Nov-06 5:41
memberPITRep16-Nov-06 5:41 
NewsMagic 1.7.4 Download link Pin
ComponentPhil10-Apr-06 2:07
memberComponentPhil10-Apr-06 2:07 
GeneralRe: Magic 1.7.4 Download link Pin
pophelix3-Oct-10 8:46
memberpophelix3-Oct-10 8:46 
GeneralBug in the control with MainMenu control Pin
bgc-waterman3-Jan-06 15:54
memberbgc-waterman3-Jan-06 15:54 
QuestionHide Tab Page Option available? Pin
chauchon9928-Aug-05 18:29
memberchauchon9928-Aug-05 18:29 
GeneralNow it is no more for free Pin
Anonymous7-Jun-05 6:57
memberAnonymous7-Jun-05 6:57 
GeneralThere is still a free version available Pin
The_Mega_ZZTer17-Aug-05 17:42
memberThe_Mega_ZZTer17-Aug-05 17:42 
GeneralUnclear As To Real Intention Pin
Mallioch18-Mar-05 2:02
memberMallioch18-Mar-05 2:02 
GeneralThe library IS free Pin
The_Mega_ZZTer17-Aug-05 17:43
memberThe_Mega_ZZTer17-Aug-05 17:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.181207.3 | Last Updated 30 Sep 2002
Article Copyright 2002 by Phil Wright
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid