Click here to Skip to main content
Click here to Skip to main content

Magic TabControl - VS.NET Style

By , 29 Sep 2002
 

Sample Image - MagicTabControl.gif

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.

Downloads

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
tab.TabPages.Clear();

// Add a single entry
tab.TabPages.Add(tabPage1);

// 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}",
                           tab.TabPages[0].Text);

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

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

// Remove by object reference
tab.TabPages.Remove(tabPage1);

// Remove by index
tab.TabPages.RemoveAt(0);   
 

Appearance

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.

Notifications

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(
                                 OnClosePressed);
   tab.SelectionChanged += new EventHandler(
                             OnSelectionChanged);

...
}

protected void OnClosePressed(object sender,
                                     EventArgs e)
{
   Console.WriteLine("OnClosePressed");
}

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

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

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

About the Author

Phil Wright
Web Developer
United Kingdom United Kingdom
Member
I am a big fan of .NET and have been working on developing a free user interface library to enhance the very basic controls that come out-of-the-box. Download the free source code project from http://www.dotnetmagic.com. I often carry out bespoke development work for companies, so feel free to email me for a quote on your .NET needs!
 


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow to call form_closing() eventmemberSomnath kadam16 Jan '13 - 21:42 
Using Magic Tabcontrol how to call form_closing() method of opened forms?
QuestionHow to know if Tab Contains a page already of the name using VB.NET?memberwmason123429 Aug '12 - 5:06 
I have the below code to check if a tab of the same name exists.
If it does, it should activate that tab.
If not, it should add the tab.
 
It appears my if statement is not correct. Can anyone help?
 

Dim page As Crownwood.Magic.Controls.TabPage
page = New Crownwood.Magic.Controls.TabPage(strTabName, formProfile, tabCtrlScreens.ImageList, 0)
 
If tabCtrlScreens.TabPages.Contains(page) Then
tabCtrlScreens.TabPages(strTabName).Selected = True
Else
tabCtrlScreens.TabPages.Add(page)
End If
GeneralUse Crownwood tabcontrol in C# 2010memberajaxswan6 Jun '11 - 7:49 
Can I uSe Crownwood tabcontrol in C# 2010 ?
QuestionTabbed web browsermemberStenio Joseph9 Jan '11 - 3:12 
Hi, My name is Stenio. I'm developing a tabbed web browser
I'd to know how to enable the right click into the tab control
to make it open a new tab.
Thank you in advance for helping me!
Stenio Joseph

GeneralMy vote of 1memberkarthikeyan198331 Aug '10 - 2:05 
Those are simple stuff by doing a sample we can explore these things.
GeneralRe: My vote of 1memberJohnny J.28 Sep '10 - 22:14 
WHAT? Please rephrase this question...
GeneralCrownwood.Magic.Controls.TabControl does not dispose its child tab pagesmemberMeleagerster27 May '10 - 15:19 
Just a note to whoever uses this, the TabControl does not dispose its TabPages when you call Dispose() (which is the expected behaviour of a control). You'll have to iterate through the TabControl and call each TabPages Dispose() function manually.
QuestionUsagememberAleksei Krassovskikh14 Jan '08 - 7:24 
Hello!
 
I am creating commercial project (shareware program) and your contol is what I looked for. So, can I use it? All copyright will be noticed in 'About' dialog.
 
If it is not difficult, can you mail your answer to krasssss@mail.ru.
 
Regards, Alex.
 
Alex KraS

QuestionVisual Studio 2005?membershubhabratam21 Oct '07 - 0:33 
Great Control you have provided. Can I use for my personal use?
 
How do I get the look % feel of Visual Studio 2005?
QuestionHow to add a minimize,maximize,restore button to tab controlmemberIftekhar Naim14 Dec '06 - 4:54 
In the tabgroup of magic library , there is a close button. But no maximize/minimize button. Can anyone tell me how to add these functionality to tabbed group.
 
Chayan

QuestiondataTableAdaptermemberppro7 Dec '06 - 14:49 
I am working with a database project. The tabcontrol will only register 2 tableadapters.
I can add a tableadapter on two pages only. The third page will initally show the detailed table but once you move off the page the table vanishes. You can add another control say a button on to the third page and it will remain.
This is a nice improvement over the standard tabcontrol but seems to have a bug here. All the initialization code is still present in the parent form and the constructors for the third adapter are there but no visual presentation!! The parent form is a standard type form not MDI or modal etc.
I would like to land up with 6 tab pages showing 6 different dataadapters. Any suggestions.

 
Paul
Generalhide an ordinary tab pagemember¤ Muammar ¤26 Nov '06 - 22:41 
hey there, the example is wonderful and i like it, but can you please help me on hiding an ordinary tab page from an ordinary tab control?? thank uSmile | :)
 
all generalizations are wrong, including this one!
GeneralRe: hide an ordinary tab pagememberGhazi Al Wadi, PMP24 Mar '07 - 2:04 
Use conrols.add and conrols.remove
 
Ghazi Hadi Al Wadi, PMP, ASQ SSGB, DBA
 

AnswerRe: hide an ordinary tab pagememberMuhammad Adil31 Jul '08 - 20:49 
That is very Intrusting To find That Microsoft Asp tab Control have confusing Property to hide and enable
Well to resolve this Issue try
To Hide Particular tab
TabContainer1.Tabs[0].Enabled = false;
To Enable Particular tab
TabContainer1.Tabs[0]. Visible = false;
 
Hope that would Resolve your Problum
Regards
Sr. Software engineer
http://www.successcodes.us
[^]
GeneralAwesome!! (NOT a sham)memberSkcheng17 Nov '06 - 18:49 
Hi there, just wanted to say that this is a great package. Sorry to see so many people calling it a sham when this article (as another poster mentioned) was posted prior to your selling it.
 
Thanks so much, you just helped me make my little program look oh so professional. Rose | [Rose] Rose | [Rose]
 
Dead | X| Over-worked, under-paid, glorified "secretary". Sigh | :sigh:
GeneralExtending Into CABmemberPITRep16 Nov '06 - 4:41 
I am working with CAB (Composite UI Application Block) and I am trying to create a new Tab Workspace using the Magic Tab Control.
 
I used the code that was supplied with CAB on thie default Tab Workspace so it works fine, except the close button. I cannot seem to capture the events being fired in my base class i created (MagicTabWorkspace : Magic.Controls.TabControl : ....). Could you either point me to some documentation on the control or something to help me out.

NewsMagic 1.7.4 Download linkmemberComponentPhil10 Apr '06 - 1:07 
I've been asked a few times recently where people can download the last available version of the Magic Library that I created some time ago. You can still get hold of version 1.7.4 and use the library in your commerical apps. Just use the following link to download it...
 
http://www.dotnetmagic.com/downloads/MagicLibrary174.msi
 
Note that this was developed under VS2003 and so I am not sure how well it will work under VS2005. In theory any changes should be pretty minor. I have recently built a free library that is aimed at .NET2. You can try this new one out at...
 
http://www.componentfactory.com/products.html
 
Regards
Phil Wright
Component Factory Pty Ltd
GeneralRe: Magic 1.7.4 Download linkmemberpophelix3 Oct '10 - 7:46 
good!ths
GeneralBug in the control with MainMenu controlmemberbgc-waterman3 Jan '06 - 14:54 
I have been working on an application that uses the tab control. I went to add a MainMenu control (VB.Net 2003)and found that the mainmenu control is hidden. I am using version 1.7.0, I will download version 1.7.4. Will this correct the problem?
Frown | :(
QuestionHide Tab Page Option available?membersanme9828 Aug '05 - 17:29 
May I know is this Magic TabControl have Hide() available for tab page. In some situation, i need to temporary hide some tab page and later show it again in others situation.
 
Thanks.
GeneralNow it is no more for freesussAnonymous7 Jun '05 - 5:57 
If tou want to develop something width this library you have TO PAY!
For more information
http://www.dotnetmagic.com/
GeneralThere is still a free version availablememberThe_Mega_ZZTer17 Aug '05 - 16:42 
Magic Library 1.7.4 is available for download as royalty-free freeware, on the site you linked to infact. It is linked from one of the articles here, even (do a search for it in the articles and you'll find it easy enough).
 
However the newer versions, called DotNetMagic, are not freeware. Frown | :(
GeneralUnclear As To Real IntentionmemberMallioch18 Mar '05 - 1:02 
Like some others, I find the presentation above to be unclear and, frankly, misleading. The code sample above is not the code of the tab control itself, but rather code to use the already compiled dll. Please be clear as to your intentions, because it looks like you're acting like you're providing free stuff while you're really just trying to get people to buy your library.
GeneralThe library IS freememberThe_Mega_ZZTer17 Aug '05 - 16:43 
The library is free, see my post above for details.
GeneralPreventing TabControl from grabbing focusmemberChefren28 Dec '04 - 2:45 
I use the TabControl in my program and fill several tabs with grids full of data. Everything works, except that I also have a progress form used when loading the data into the interface. The progressbar in the form fails to refresh because the TabControl grabs focus whenever it updates. Calling Refresh() and DoEvents() don't help. Neither does "Call ShowWindow(Me.Handle.ToInt32, SW_SHOWNOACTIVATE)". The progress windows becomes unfocused when the first tab is drawn and does not redraw. How can I prevent the tabcontrol from grabbing focus like this? Disabling it or hiding won't work.
 
I use the very same form when committing the data back to the database and here my progressform works like a charm. The problem did not exist when I used the regular .net tabcontrol.
GeneralRe: Hide the tab controlmemberke_prabha9 Feb '05 - 18:34 
abhu
GeneralTab Page Size not increasingsussashishacharya7 Nov '04 - 19:27 
Hi,
 
Basically i have a form designer sort of application on which i have used Magic TabControl. On top there is toolbar which has Dock property set to "Top". On Left there is "TreeView" whose Dock property is set to "Left". On right there is PropertyGrid with dock property set to "Right" On bottom there is StatusBar whose Dock property is set to "Bottom". Last but not the least there is a Tabcontrol in Middle of them all whose Dock proeprty is set to "Fill".
Now on the TabControl there is a Tabpage which has a custom control derived from Form. I drag and drop control on this custom control. I have set the AutoScroll property of this usercontrol as "True".
 
Now problem is the size of the form control does not increase even if i drag a control on form beyond its vertical boundary. The vertical scrollbars appears but the size of the custom control lying on the TabPage Control on the TabControl does not increase. Hence the location of the dragged control on the Form does not increase beyond a certain limit.
 
Can anybody tell why this is happening ? I am really struck up.
 
Ashish Acharya
GeneralRe: Tab Page Size not increasingmemberashishacharya24 Nov '04 - 2:10 
Hi,
 
Finally solved the problem. Now i put two layers of panel on the tabpage. The first layer has its dock property set to DockStyle.Fill and second layer has its AutoScorll property set to false dock property set to "None".
 
Ashish
GeneralA little bug!memberJordi Corominas4 Nov '04 - 21:39 
Hi!
 
If I put a treeView or a listView wich contains images and this control is in the first tabPage the images are not painted. I'm sure that the problem is only on the first page because I have 4 pages and 2 of them contain .net controls with pictures (1 treeView and 1 listView). I've tried diferent orders of the tabpages and when one of this pages is in the first position the images aren't painted. Any solution?
 
Thank you!
 
"Catalonia is not Spain"
GeneralRe: A little bug!memberJordi Corominas10 Nov '04 - 2:57 
Any comment?
 
"Catalonia is not Spain"
GeneralLatest version of librarymemberchito16 Aug '04 - 14:17 
Hai All,
Where can I find latest free version of magic library?
Thanks,
Chito.
GeneralRe: Latest version of librarymemberszalony_jack_pirat25 Oct '04 - 1:44 
http://dev.cdrnet.net/download/ThirdParty/MagicUI/1.7.4/MagicInstall174.zip
GeneralRe: Latest version of librarymemberThe_Mega_ZZTer17 Aug '05 - 16:44 
To clarify, that is the latest freeware version. All versions after that are not freeware. Frown | :(
QuestionCan I add pages Vertically in magic TabControlmemberArchana19773 Aug '04 - 3:36 
Hi
 
I am developing one application in C#.
This has really high importance for look and feel.
So I started using Magic Tab Control instead of Windows Tab Control.
 
But now i am stuck as I want to add Tab pages Vertically one below each other.
I can do this in Windows Tab control using property "Alignment". But I could not find similar property in Magic tab Control.
Can somebody help me out?
Thanks in advance.

 
Archana
QuestionHow to change image size of images displayed in tabs?memberPradeep Maskeri2 Jun '04 - 14:05 
Changing imagelist image size in properties or in code does not change the size of images displayed in tabs. It remains 16 x 16.
 
Is there a way?
GeneralThis is a sham!memberaprenot25 May '04 - 18:03 
Code project is about CODE!! This is just a ploy from the Author to promote his control suite. Now I am not against programmers making money (I am one after all), but don't use a source code collaboration board to promote it. Who cares about how to use this control. We should be able to gather that from your help docs, and samples on your website. I am interested in how these controls work!
 
aprenot
GeneralRe: This is a sham!memberbragac20012 Jun '04 - 6:52 
This really is a sham, I can't beleive the editors of this site are letting this sort of stuff in.
GeneralRe: This is a sham!sussCroaker Norge16 Jun '04 - 13:17 
It's not a sham, folks. He's selling the new versions, but the full source is available for this old version. It works really well, looks great, no royalties. I really like it quite a lot.
GeneralRe: This is a sham!memberbcorazza11 Jul '04 - 9:24 
Big Sham. It is ALL about the CODE. Sell your software by being a sponser of CodeProject, not by posting this stuff here.Frown | :(
GeneralRe: This is a sham!member
MadHatter ¢
9 Sep '04 - 2:50 
actually this article pre-dates his for sale version. it was once the library of choice, which was used by SharpDevelop, but once he started selling it, most just still use the open source one. this article is also a very early version of that library.
 



/bb|[^b]{2}/
 

GeneralSelectionChanging Eventmembermatzy21 May '04 - 3:36 
This is a great control! The only gripe I have is that the SelectionChanging event handler doesn't use a Cancel EventArgs like the TreeView control has. I'm trying to run some validation logic in the SelectionChanging event, and would like to cancel the change if validation fails. I tried setting the selected page, but it still continues on to the next tab. Any ideas?
GeneralCrownwood.Magic.Controls.TabControlmemberArunkKumar14 May '04 - 21:28 
hi,
 
I am using MagicControl 1.7.1.0.
I wanted to have drag n drop feature on the tab control and i could do it on the System.Windows.Forms.TabControl (with the help of GetTabRect(), i could get the tabpage at the mouse location). I dint find any similar API on the this version of Crownwood.Magic.Controls.TabControl.
 
Have any one stuck with the similar issue and found a solution ? Wink | ;)
 
Thanks in advance

GeneralRe: Crownwood.Magic.Controls.TabControlmemberJeffPHP28 Sep '05 - 6:21 
I have the same exact problem.
 
Even tabPages don't give their own Location.X, Location.Y, Bottom, Right, Width but the one of the containing TabControl...
 
So it's impossible to get the clicked tabPage (with a right mouse button click or a drag'n'drop).
 
If you found any issue, could you please tell me ?
 

GeneralGood!memberNorm Almond15 Apr '04 - 4:34 
A worthy 5 my friend.

GeneralNeed help to disbale Windows Start Menu and Task barsusscodeshredder12 Mar '04 - 2:43 
If any one know C# code to disable Windows Task bar and Start menu please post it
Thanks
GeneralCode generation failedmemberandroboy1 Mar '04 - 17:43 
I am receiving this error message from VS.NET 2003:
 
Code generation for property 'Controls' failed. Error was: 'Object reference not set to an instance of an object.'
 
I placed MagicLibrary.dll in to my D:\DotNetTools folder.
 
Then added a new toolbox tab in VS.NET and added the .NET framework components from MagicLibrary.dll in D:\DotNetTools.
 
I was unable to drag and drop an instance of any Magic Library tools at this point. So I added a project reference to MagicLibrary.dll. After that I could use the components in the form designer.
 
I added a new tabPage to my Crownwood TabControl, then went to View the code-behind. At this point, I always get the Code Generation error msg.
 

Any ideas?

GeneralThis TabControl is so greatmemberJcxl25 Feb '04 - 20:25 
Have open sources? if have ,send to me?
 
design by vc++.net?or c#?
 
Smile | :) Smile | :) Smile | :)
GeneralvisualAppearance bugs.memberMarcel Sorger15 Jan '04 - 3:41 
The tabpages always end up below the page because visualAppearance is an undefined enum.
I solve the problem by setting the visualAppearance at runtime, but in the designer this does not work.
The designer promply undo's all the changes to the tabcontrol and put the tabpages at the botom.
(It iritates the hell out of me Mad | :mad: )
 
Any idea why this might happen?
 

Generalpaint methodmemberergunozyurt29 Dec '03 - 6:20 
paint method of tab control is not working?
QuestionHow to use TabbedGroupsmemberdev_kh16 Dec '03 - 4:47 
Hi,
 
I wanted the ability to drag and drop tab items on top of other tab items (not mdi documents) in .Net win project. So I downloaded and installed the magic library, but I cannot find any instructions on how to start using the tabbedgroups in vb.net (According to my understanding the tabbedgroups should give me the required functionality)
 
Is there any such link which gives these instructions, like how to setup and configure the tabbedgroup.

 

Thanks
dev_kh

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

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