(WORK IN PROGRESS!)
UPDATE: No longer uses a tabcontrol in a tabcontrol-usercontrol. Just one custom tabcontrol, one designer and one custom tabpage control.
Here is a TabControl (with custom(izable) TabPages) that includes the following:
- Standard TabControl look and feel
No ugly custom drawing. But ofcourse, if you want to have custom drawing, there is nothing that stops you!
- Design-time support
It is possible to switch, add and remove TabPages in the Designer like you can with the normal TabControl.
- Tab-specific ContextMenuStrips
Rightclicking a TabPage will bring up a ContextMenuStrip of your choice. The ContextMenuStrip is a property of the TabPage, so you can have a different (or none) ContextMenuStrip for each TabPage.
- Draggable Tabs (even from one TabControl to the other)
Drag tabs with your mouse to change the order of the tabs, or even drag them from one of my custom TabControls to another.
- ... Possibly more when I finish it!
A lot of work went into getting the Design-time support to work. Usually, when you Inherit from the TabControl, you get the Design-time support automatically. However, (I think) if you want to use custom TabPages, you need to create your own Designer. I don't know if it was really necessary to do it the way I did, but after trying hundreds of things I felt I was forced to make my own Custom Designer.
So in addition to being a 'normal' TabControl with enhanced functionality, this is also an example of a pretty complicated custom Designer.
Credits to Mick Doherty for his TabControl Tips. This is where I got much of the Designer class from, thanks!
Here is a short explanation of the various classes in my example:
The main TabControl is the cTabControl.
If you open the code of the cTabControl class, you can see how the Designer is applied:
The cTabControlDesigner class enables the Design-time tab switching, and also adds the DesignerVerbs (or Smart-Tags) "Add TabPage", "Insert TabPage" and "Remove TabPage".Code:<Designer(GetType(cTabControlDesigner))> _ Public Class cTabControl
Then, there is the custom TabPage cTabPage class. This is merely a usercontrol Inheriting from the windows TabPage, with one extra Property: TabHeaderContextMenuStrip. This is the ContextMenuStrip that shows when you rightclick the tab's header (and can be set via code OR in the designer).
You can also see that the cTabPage uses the ScrollableControlDesigner which is a standard designer.
Please note that this is still a work in progress. There are many things that don't work properly yet.
- don't try to drag a TabPage via the 'move icon' in the designer, VS will crash.
An example project is attached. You may need to Build or run the project to get rid of any warnings.