Results 1 to 15 of 15

Thread: Customizable TabControl

  1. #1

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Talking Customizable TabControl

    Update: Added features. Now version 0.6

    Critical Update: Fixed Bugs. Now Version 0.5.1

    A customizable TabControl? No way! Now it's here. It is a bit slow on old computers, but I'm working on that.

    I've been stuck with the default TabControl forever, and been held back by its limitations.

    Features:
    • Customizable tab headers (using the XTabStyle.IHeaderRenderer interface)
    • Optional double-buffering (use the DoubleBuffer write-only property)
    • Great design-time support
    • Transparent and semi-transparent background colors
    • And much more!


    Features I hope to release in later versions:
    • Additional default IHeaderRenderers
    • Smart Tags
    • More speed
    • Property descriptions and XML comments
    • An overflow list
    • Hot-tracking
    • The ability to change tabs by clicking instead of using the SelectedIndex property
    • More events


    Enjoy! Please let me know about any bugs, this is version 0.5.

    You can also get the DLL here.
    Attached Files Attached Files
    Last edited by minitech; Apr 29th, 2010 at 07:10 PM. Reason: Updated to version 0.6

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Customizable TabControl

    I added it to a new project, fixed the import statement and was able to build the project.

    I added the TabControl to the form (really ugly default color, btw) I then added 3 tab pages to the TabPageArray and the first thing I noticed was that I can't click the tab header to switch to the other pages to add controls to it. Before I added anything to any of the tab pages I tried running it with just the three empty tabs and got this error and the form wouldn't show:
    Code:
    System.InvalidOperationException was unhandled
      Message="An error occurred creating the form. See Exception.InnerException for details.  The error is: The selected index must be less than the number of tabs in the XTabControl."
      Source="WindowsApplication1"
      StackTrace:
           at WindowsApplication1.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
           at WindowsApplication1.My.MyProject.MyForms.get_Form1()
           at WindowsApplication1.My.MyApplication.OnCreateMainForm() in C:\Users\JuggaloBrotha\Desktop\WindowsApplication1\WindowsApplication1\My Project\Application.Designer.vb:line 35
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
           at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.ArgumentException
           Message="The selected index must be less than the number of tabs in the XTabControl."
           Source="WindowsApplication1"
           StackTrace:
                at WindowsApplication1.XTabControl.set_SelectedIndex(Int32 value) in C:\Users\JuggaloBrotha\Desktop\WindowsApplication1\WindowsApplication1\XTabControl.vb:line 63
                at WindowsApplication1.Form1.InitializeComponent() in C:\Users\JuggaloBrotha\Desktop\WindowsApplication1\WindowsApplication1\Form1.Designer.vb:line 47
                at WindowsApplication1.Form1..ctor()
           InnerException:
    I've attached the project too.
    Last edited by JuggaloBrotha; Jun 30th, 2010 at 02:43 PM.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  3. #3
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Customizable TabControl

    I've got the same problem as JuggaloBrotha, form won't show, something with a selected index out of range.

    Also, the imports statement is wrong (I think you may have renamed the project or something but didn't rename the import statement).

    Oh, and you can move the tabpages around (fix this in the designer for the tabpages, override the SelectionRules property and return Locked).


    For your updates, you may want to check out most of the control here if you haven't already:
    http://dotnetrix.co.uk/tabcontrol.htm

    He shows you how to add design-time support for the tab control (selecting the headers), and much more. I think I have implemented the same thing in my tabcontrol with contextmenu, see my signature.

    I also have a codebank submission on the Smart Tags I think, although I haven't got that in my signature for some reason. Try searching for it (try "Smart-Tag" or "Smart Tag" or other combinations or you won't find it).

  4. #4

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Customizable TabControl

    Quote Originally Posted by JuggaloBrotha View Post
    I added it to a new project, fixed the import statement and was able to build the project.

    I added the TabControl to the form (really ugly default color, btw) I then added 3 tab pages to the TabPageArray and the first thing I noticed was that I can't click the tab header to switch to the other pages to add controls to it. Before I added anything to any of the tab pages I tried running it with just the three empty tabs and got this error and the form wouldn't show:
    Code:
    System.InvalidOperationException was unhandled
      Message="An error occurred creating the form. See Exception.InnerException for details.  The error is: The selected index must be less than the number of tabs in the XTabControl."
      Source="WindowsApplication1"
      StackTrace:
           at WindowsApplication1.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
           at WindowsApplication1.My.MyProject.MyForms.get_Form1()
           at WindowsApplication1.My.MyApplication.OnCreateMainForm() in C:\Users\JuggaloBrotha\Desktop\WindowsApplication1\WindowsApplication1\My Project\Application.Designer.vb:line 35
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
           at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.ArgumentException
           Message="The selected index must be less than the number of tabs in the XTabControl."
           Source="WindowsApplication1"
           StackTrace:
                at WindowsApplication1.XTabControl.set_SelectedIndex(Int32 value) in C:\Users\JuggaloBrotha\Desktop\WindowsApplication1\WindowsApplication1\XTabControl.vb:line 63
                at WindowsApplication1.Form1.InitializeComponent() in C:\Users\JuggaloBrotha\Desktop\WindowsApplication1\WindowsApplication1\Form1.Designer.vb:line 47
                at WindowsApplication1.Form1..ctor()
           InnerException:
    I've attached the project too.
    Um, really? I've already built a tabbed WebBrowser with it. And thanks for the color comment, I chose those because I thought they went really well with the default Control grey. Guess I was wrong Of course you can't click the tab pages to switch, I actually mentioned that in my post. Obviously you didn't read it through. I'll take a look at your project.

  5. #5

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Customizable TabControl

    P.S. What is the Imports problem you're talking about?

    P.P.S. @NickThissen: I know how to add these, I'm just working on the design right now.
    About the movable tabs, I'm not sure why, but there is no System.Windows.Forms.Design.ControlDesigner class, so I can't inherit it.
    Last edited by minitech; Apr 25th, 2010 at 05:08 PM.

  6. #6

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Customizable TabControl

    Well, I got your error and I'm trying to track it down. In the meantime, could you try the DLL? That's what I used for my tabbed browser, and it seems to work.

  7. #7

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Customizable TabControl

    Ok, it looks like the designer is deserializing the SelectedIndex property before the TabPagesArray (I wonder why it doesn't happen to me?)

    I'll upload a fixed copy. Thanks for pointing that out!

    P.S. There's an Imports problem because the control was developed in a project called "TabControlPlus". I've added a comment in the code now.

  8. #8

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Customizable TabControl

    Updates complete!

  9. #9
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Customizable TabControl

    Quote Originally Posted by minitech View Post
    P.S. What is the Imports problem you're talking about?

    P.P.S. @NickThissen: I know how to add these, I'm just working on the design right now.
    About the movable tabs, I'm not sure why, but there is no System.Windows.Forms.Design.ControlDesigner class, so I can't inherit it.
    You need to add a reference to System.Design.

  10. #10

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Customizable TabControl

    Add a reference to System.Design to use System.Windows.Forms.Design? That's strange. Ok, I'll try that.

  11. #11
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Customizable TabControl

    Quote Originally Posted by minitech View Post
    Add a reference to System.Design to use System.Windows.Forms.Design? That's strange. Ok, I'll try that.
    Yes, the System.Windows.Forms.Design namespace is in the System.Design.dll assembly.

    It says so right in MSDN:
    http://msdn.microsoft.com/en-us/libr...ldesigner.aspx
    ControlDesigner Class

    Extends the design mode behavior of a Control.

    Namespace: System.Windows.Forms.Design
    Assembly: System.Design (in System.Design.dll)
    The name of the namespace doesn't have to match the name of the assembly, even though it almost always does in the .NET framework. I suppose they kept the Design namespace in a separate DLL because most people never use it anyway.

  12. #12

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Customizable TabControl

    I've changed the designer for the code, but now the TabPages appear in the Components area underneath the form (where Timers appear). I guess the next version won't be released for a while!

    Anyways, I'm adding hot-tracking and close buttons.

    EDIT: Never mind, it just randomly stopped!
    Last edited by minitech; Apr 29th, 2010 at 06:57 PM.

  13. #13

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Customizable TabControl

    Updates complete!

  14. #14

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Customizable TabControl

    For people who don't like the color (not a huge suprise), you can make your own header renderer! Here's how:

    Either implement IHeaderRenderer (harder) or inherit DefaultHeaderRenderer (easy, but less control).

    Inheriting DefaultHeaderRenderer (implementing coming soon, but you should be able to figure it out):

    Code:
    Public Class MyHR : Inherits XTabStyle.DefaultHeaderRenderer
    End Class
    Change the border color by overriding:
    Code:
    Public Class MyHR : Inherits XTabStyle.DefaultHeaderRenderer
         Protected Overrides Function GetBorderColor() As Color
              Return Color.White
         End Function
    End Class
    Change the text color, again by overriding:
    Code:
    Public Class MyHR : Inherits XTabStyle.DefaultHeaderRenderer
         Protected Overrides Function GetBorderColor() As Color
              Return Color.White
         End Function
         Protected Overrides Function GetTextColor() As Color
              Return Color.DarkGreen
         End Function
    End Class
    Change the font:
    Code:
    Public Class MyHR : Inherits XTabStyle.DefaultHeaderRenderer
         Protected Overrides Function GetBorderColor() As Color
              Return Color.White
         End Function
         Protected Overrides Function GetTextColor() As Color
              Return Color.DarkGreen
         End Function
         Protected Overrides Function GetFont() As Font
              Return New Font("Verdana",11.0!)
         End Function
    End Class
    Change the tab background:
    Code:
    Public Class MyHR : Inherits XTabStyle.DefaultHeaderRenderer
         Protected Overrides Function GetBorderColor() As Color
              Return Color.White
         End Function
         Protected Overrides Function GetTextColor() As Color
              Return Color.DarkGreen
         End Function
         Protected Overrides Function GetFont() As Font
              Return New Font("Verdana",11.0!)
         End Function
         Protected Overrides Function GetBrush(ByVal size As Size) As Brush
              Return New SolidBrush(Color.Black) 'In this example, I change the background to solid black.
         End Function
    End Class
    Finally, set the XTabControl's HeaderRenderer property to an instance of your class.

    Code:
    Me.XTabControl1.HeaderRenderer = New MyHR()
    Last edited by minitech; May 10th, 2010 at 07:04 PM.

  15. #15

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Customizable TabControl

    Contest time: make the best tab header renderer! The top 5 elected will be included in the package. I'll add a poll for the best ones. It won't take too much time; see how easy that last example was?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width