Results 1 to 3 of 3

Thread: [2005] Custom TabControl

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    [2005] Custom TabControl

    I am trying to draw a custom tab control. What I need is to be able to create different sizes for the tabs. I can do it easily if I want them the same size.

    I've tried changing the ItemSize of the tabcontrol in the DrawItem event, but that made the control very unhappy. I also looked at the events of the tab page and I didn't see anything there that would do it.

    Any help would be great. Thanks.

    Edit:
    I know that setting the sizemode to Normal will make it the size of the text. But what I want to do is if the text is larger than a certain amount it will only show part of it, unless it is selected, then it will show the entire text.
    Last edited by mpdeglau; Jul 24th, 2006 at 10:34 AM. Reason: Added more info
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Custom TabControl

    you could just change the text when the tabs are changed..

    for example.. lets say you set each tabs TAG property, to the same as its text property.. (if you already use TAG for something else, you could just keep the data in a local array instead) then you add some code like this
    VB Code:
    1. 'NUMBER OF CHARACTERS TO SHOW IN UNSELECTED TABS (PLUS ...)
    2.     Private Const MAX_TAB_CHARS As Integer = 12
    3.  
    4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         TruncateTabs()
    6.     End Sub
    7.  
    8.     Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
    9.         TruncateTabs()
    10.     End Sub
    11.  
    12.     Private Sub TruncateTabs()
    13.         'SHORTEN TABS THAT ARE LONGER THAN THE MAX_TAB_CHARS SETTING
    14.         For Each TP As TabPage In TabControl1.TabPages
    15.             If Not TP Is TabControl1.SelectedTab Then
    16.                 If TP.Tag.ToString.Length > MAX_TAB_CHARS Then
    17.                     TP.Text = TP.Tag.ToString.Substring(0, MAX_TAB_CHARS) & "..."
    18.                 End If
    19.             Else
    20.                 TabControl1.SelectedTab.Text = TabControl1.SelectedTab.Tag.ToString
    21.             End If
    22.         Next
    23.     End Sub
    so that when the user clicks on the tab, the full text is shown, but all the others are truncated to whatever length you want.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [2005] Custom TabControl

    This works....But it doesn't do, exactly what I'm trying to do. I don't think I was very clear in my first post (Monday morning after a weekend of 100 plus degree temperature with no AC will do that to you).

    Lets say I have 6 tabs. The text on each one of different length. The tab control has a width of 320. What I want to do is when a page is selected, the full text shows. The rest of the tab pages get truncated to fill the remaining space.

    So if the selected tab is 100 pixels wide, then the other 5 will be 64 pixels wide.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

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