0

How do you hide the tabs of a tab control in order to do dynamic page changes where it looks like everything on the form disappeared and something new entirely appears?

This is useful for Wizards as well as those one page 'list of settings on left side, page of those settings on right side' configuration pages you see in IDE's so often.

Script and Compile
  • 1,286
  • 3
  • 10
  • 17
  • possible duplicate of [Creating Wizards for Windows Forms in C#](http://stackoverflow.com/questions/2340566/creating-wizards-for-windows-forms-in-c-sharp) – Idle_Mind Jan 07 '15 at 18:55
  • It's a duplicate, but I keep seeing this same problem coming up all over and the same 'solution' to the problem. – Script and Compile Jan 07 '15 at 19:09

1 Answers1

0

Hiding tabs or "I want to dynamically change a form between a set of item content"

I had huge issues pulling this off before. There are a couple example ways of doing this online, and each of them come with some serious issues. Namely lack of design time visibility platform dependency (windows only) as well as internal magic or some serious subclassing and reimplementation of what is tab controls.

One suggested way of pulling this trick off is to absorb the windows message for tab drawing. This works but it's OS dependent and it looks very weird accessing the windows pump like that in .net.

another suggestion I've seen is to build from scratch a tab control and then just not implement tab drawing....

The way to solve this problem is very simple. All of these items can be found in the TabControl designer properties.

tabControl.Appearance = FlatButtons;
tabControl.SizeMode = Fixed;
tabControl.ItemSize.Width = 0;
tabControl.ItemSize.Height = 1;

tada! tabs are hidden. Now create a tab per 'set' of dynamic controls you want to hide and show and do standard databinding.

To make this a tad more user friendly (in cases where you are working on a large application or building this as a standard component you will use often) subclass the tabcontrol and do a design time check and unset these values so you can see the tabs for designing. this has other issues involving layout if you are using a fixed layout model (bad bad!)

This solution does have some caveats. Namely, you can still tab to the tab control and then change pages. This can be fixed by hooking into the Enter event for the control and then pass focus to the first tab element in the selected tab.

Another problem is that if the tab control is too small then you get a small left/right button on the right hand side (when using left to right languages, left side otherwise) which allow you to select between tabs. I do not know of a solution to that issue.

Script and Compile
  • 1,286
  • 3
  • 10
  • 17