[UPDATE] Custom TabControl incl Designer, Tab-specific ContextMenus and Tab-Dragging
(WORK IN PROGRESS!)
UPDATE: No longer uses a tabcontrol in a tabcontrol-usercontrol. Just one custom tabcontrol, one designer and one custom tabpage control.
--------------
Hi,
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:
Code:
<Designer(GetType(cTabControlDesigner))> _
Public Class cTabControl
The cTabControlDesigner class enables the Design-time tab switching, and also adds the DesignerVerbs (or Smart-Tags) "Add TabPage", "Insert TabPage" and "Remove TabPage".
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.
For example:
- 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.
Last edited by NickThissen; Dec 5th, 2008 at 11:57 AM.
Re: [UPDATE] Custom TabControl incl Designer, Tab-specific ContextMenus and Tab-Dragg
I love it, thanks.
Firstly, a tip: If you don't want the cursor changing (let it stay the default one), add this to cTabControl.vb:
Code:
Protected Overrides Sub OnGiveFeedback(ByVal e As System.Windows.Forms.GiveFeedbackEventArgs)
e.UseDefaultCursors = False
End Sub
Secondly, however, the control flickers alot on my computer when dragging, especially when there is a complex control on it (there is an advanced rich text editor on the tab page). Is there any way to solve this?
Re: [UPDATE] Custom TabControl incl Designer, Tab-specific ContextMenus and Tab-Dragg
Hey,
I didn't even remember this control, haha. I found a way around the cursor problem. The problem is that I initiate a drag operation immediately when the cursor moves. That's not the default behavior for dragging, usually the user has to drag the mouse outside of a small rectangle (the size of this rectangle can be obtained from SystemInformation.DragSize or something), but I did not implement that here because I didn't know about it.
As for flickering, that is most probably because when you are dragging the control is constantly removing and re-adding all tabpages (at least when you drag the page to another position). I don't know any way around this at the moment.
Re: [UPDATE] Custom TabControl incl Designer, Tab-specific ContextMenus and Tab-Dragg
How do I get the "X" icon on the tab for closing? I saw a graphic sample of your control and was immediately interested. I am using another design and not pleased with appearance.
***************************************************
Smartacus comes packaged "As Is With No Warranty"