Kevin Dente's Blog

The Blip in the Noise
Tab control with no visible tabs
One of my co-workers wanted to use a Windows Forms (2.0, in this case) TabControl as a way of swapping between sets of controls, but without display the actual tabs (controlling the switching entirely through code - a sort of swappable panel stack). After some fiddling around with various control settings, I found that  the following seems to work:
  1. Set SizeMode to Fixed.
  2. Set ItemSize to 0,1. The control won't let you set a size of 0,0, but 0,1 seems to have the desired effect.
  3. Set Appearance to Buttons. This removes the tab control border.
And that's it. You can work with the tab pages easily in the designer, and use the TabControl properties to set the active tab at runtime.

Update - One limitation with this approach is that you can't easily change the background color of a tab control. So if you want, for example, a white background on your form, you're out of luck.

Published Monday, November 14, 2005 9:19 PM by kevindente

Filed under: ,

Comments

# re: Tab control with no visible tabs@ Tuesday, November 15, 2005 12:53 PM

Why did he want to use the TabControl instead of Panels or ...? Was it Tai?

jason

# re: Tab control with no visible tabs@ Tuesday, November 15, 2005 5:11 PM

Because stacking Panel controls on top of each other makes for an ugly design-time experience (and yes, it was Tai).

Kevin Dente

# re: Tab control with no visible tabs@ Thursday, November 17, 2005 1:15 AM

Ah. I can appreciate that.

jason

# re: Tab control with no visible tabs@ Friday, November 18, 2005 10:32 AM

What fun - playing "guess the developer who asked the question". Kevin - can you provide more example questions? Then we can try to guess who asked it :) :).

RB

# re: Tab control with no visible tabs@ Tuesday, November 22, 2005 3:32 PM

Now if only we could have the Wizard 97 option. Why was that never implemented in .NET even though it's in the Win32 API?

Borid Zakharin

# re: Tab control with no visible tabs@ Tuesday, September 26, 2006 9:43 AM

uh... and tabcontrol1.visible = false was too hard to implement?

bob

# re: Tab control with no visible tabs@ Wednesday, September 27, 2006 11:21 AM

Bob,

I think you missed the idea - show the tab control and tab contents, but without showing the tab headers.

kevindente

# re: Tab control with no visible tabs@ Tuesday, January 16, 2007 7:08 AM

thanks man, that working! this is a really good way to avoid switch between two panel in the same range.

Steven

# re: Tab control with no visible tabs@ Wednesday, July 25, 2007 11:54 AM

Thanks, this is exactly what I was looking for.

Sergey

# re: Tab control with no visible tabs@ Saturday, August 25, 2007 9:28 AM

Many thanks

francois

# re: Tab control with no visible tabs@ Sunday, September 02, 2007 1:48 AM

You are so smart! thanks

Fred

# re: Tab control with no visible tabs@ Friday, September 28, 2007 8:30 AM

it doesn't work! (border is still visible)

a63kc8

# re: Tab control with no visible tabs@ Wednesday, January 09, 2008 11:32 AM

you are simply great!!

This is what i was looking for

Naveen Bhat

# re: Tab control with no visible tabs@ Saturday, April 26, 2008 9:50 PM

Thanks for the hint. It's work perfectly!

oorduz

# re: Tab control with no visible tabs@ Wednesday, September 24, 2008 6:33 AM

Great, thank you very much, made my life much easier!! :)

foamliu

# re: Tab control with no visible tabs@ Wednesday, November 19, 2008 4:15 PM

thanks, it's work great!

dehasio

# re: Tab control with no visible tabs@ Thursday, April 23, 2009 7:26 AM

Many thanks!!!

M

# re: Tab control with no visible tabs@ Thursday, August 13, 2009 11:24 AM

This is also what I do for make an easy swap between group of controls.

The problem is the borders of tabcontrol.

But your solution don't works.

I use VS 2008 and VB.NET, or C#.

Sorry.

Riccardo

# re: Tab control with no visible tabs@ Tuesday, October 20, 2009 4:33 AM

Thanks, a perfect way to create a wizard.

Those who say it doesn't work might try actually RUNNING the program, if the tabs would be invisible at design time it would be a tad harder to change to another one :)

I had constructed another approach already that also worked, but it required a bit more code: put a panel on each tab, keep the tab control invisible at runtime.  When a page has to be shown, set the parent of the corresponding panel to the form (after setting the parent of the current page back to be its tabpage) and voila - the panel's contents magically appear.

Something a bit like this:

me.suspendlayout()

if CurrentPage isnot nothing then

 CurrentPage.parent = TabPage1

end if

Panel2.parent=Me

CurrentPage = Panel2

me.resumelayout()

(Suspend/ResumeLayout speeds up switching and avoids flicker on complex pages).

Luc

Leave a Comment

(required) 
(required) 
(optional)
(required)