Results 1 to 15 of 15

Thread: tabcontrol tab color.... [twice resolved]

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Resolved tabcontrol tab color.... [twice resolved]

    In VB6, there was an issue of not being able to color just the tabs of the tab control. It appears this is still the case in .net, yes? Does anyone have a way to paint the tabs of the tab control, I'm stuck
    thanks
    kevin
    Last edited by kebo; May 3rd, 2005 at 03:43 PM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  2. #2

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: tabcontrol tab color....

    ok, I guess it is still a problem, and I will assume no one has it figured out yet without but a third party control..... so.......

    how could I figure out where the tabs are and use a graphic method to color them manually? or
    how can I get the area in the image below?
    Any idea's?
    kevin
    Attached Images Attached Images  
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: tabcontrol tab color....

    Have you tried Inheriting the Tab ccontrol in a class and overridding the OnPaint event?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: tabcontrol tab color....

    that's how I would do it, but the problem I see is getting the right edge of the last tab since I only want to paint the area to the right of all of the tabs so it doesn't look all corny and stuff
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: tabcontrol tab color....

    Ah, not the actual tabs but the blank area. How about drawing over it using the Graphics namespace? Since it probably doesnt
    move or resize it should be easy to cover it with a color or gradient you want.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: tabcontrol tab color....

    yeah, I'm gonna work on it....in the mean time I found this code to paint the tabs here and it works pretty well


    just drop a tab control on a form with DrawMode = OwnerDrawFixed and put a couple of tab pages in it
    VB Code:
    1. Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
    2.  
    3.         'Firstly we'll define some parameters.
    4.         Dim CurrentTab As TabPage = TabControl1.TabPages(e.Index)
    5.         Dim ItemRect As Rectangle = TabControl1.GetTabRect(e.Index)
    6.         Dim FillBrush As New SolidBrush(Color.Red)
    7.         Dim TextBrush As New SolidBrush(Color.White)
    8.         Dim sf As New StringFormat
    9.         sf.Alignment = StringAlignment.Center
    10.         sf.LineAlignment = StringAlignment.Center
    11.  
    12.         'If we are currently painting the Selected TabItem we'll
    13.         'change the brush colors and inflate the rectangle.
    14.         If CBool(e.State And DrawItemState.Selected) Then
    15.             FillBrush.Color = Color.White
    16.             TextBrush.Color = Color.Red
    17.             ItemRect.Inflate(2, 2)
    18.         End If
    19.  
    20.         'Set up rotation for left and right aligned tabs
    21.         If TabControl1.Alignment = TabAlignment.Left Or TabControl1.Alignment = TabAlignment.Right Then
    22.             Dim RotateAngle As Single = 90
    23.             If TabControl1.Alignment = TabAlignment.Left Then RotateAngle = 270
    24.             Dim cp As New PointF(ItemRect.Left + (ItemRect.Width \ 2), ItemRect.Top + (ItemRect.Height \ 2))
    25.             e.Graphics.TranslateTransform(cp.X, cp.Y)
    26.             e.Graphics.RotateTransform(RotateAngle)
    27.             ItemRect = New Rectangle(-(ItemRect.Height \ 2), -(ItemRect.Width \ 2), ItemRect.Height, ItemRect.Width)
    28.         End If
    29.  
    30.         'Next we'll paint the TabItem with our Fill Brush
    31.         e.Graphics.FillRectangle(FillBrush, ItemRect)
    32.  
    33.         'Now draw the text.
    34.         e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, RectangleF.op_Implicit(ItemRect), sf)
    35.  
    36.         'Reset any Graphics rotation
    37.         e.Graphics.ResetTransform()
    38.  
    39.         'Finally, we should Dispose of our brushes.
    40.         FillBrush.Dispose()
    41.         TextBrush.Dispose()
    42.     End Sub
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: tabcontrol tab color....

    Very nice Thanks for sharing it. I dont think I remember seeing any code on the Forums for .NET Tab control tab coloring.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: tabcontrol tab color....

    Quote Originally Posted by RobDog888
    Ah, not the actual tabs but the blank area. How about drawing over it using the Graphics namespace? Since it probably doesnt
    move or resize it should be easy to cover it with a color or gradient you want.
    I have worked on it, but don't see why it doesn't work. using mouse move events, it appears the the blank region is part of the form (at least it responds to form events so I have tried this code
    VB Code:
    1. Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
    2.  
    3.         Dim fb As New SolidBrush(Color.Black) 'Me.BackColor)
    4.         Dim LastTabRect As Rectangle = TabControl1.GetTabRect(TabControl1.TabPages.Count - 1)
    5.         Dim Rect As Rectangle
    6.  
    7.         Rect.Location = New Point(LastTabRect.Right + TabControl1.Left, TabControl1.Top)
    8.         Rect.Size = New Size(TabControl1.Right - Rect.Left, LastTabRect.Height)
    9.         e.Graphics.FillRectangle(fb, Rect)
    10.  
    11.         fb.Dispose()
    12.  
    13.         Label2.Text = "rect location = " & Rect.X & ", " & Rect.Y & ", Size = " & Rect.Width & ", " & Rect.Height
    14.     End Sub
    based on the mousemove feedback, the rectanlge looks like it's in the right spot, but it doesn't paint over the blank area. Can you see what's wrong? Maybe I'm painting on the wrong object?
    here's the project too.
    thanks
    kevin
    Attached Files Attached Files
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: tabcontrol tab color.... [1/2 resolved]

    Your painting behind the tab control, on the form and not on the tab control.
    You need to Inherit in a classs the tab control so you can get access to the OnPaint event. There may be another
    way to draw on the control without inheriting. I'll look into it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: tabcontrol tab color.... [1/2 resolved]

    This is another option for drawing on the tab control without inheriting. Although I didnt get it to paint yet,
    but the option is there.

    VB Code:
    1. TabControl1.CreateGraphics.FillRectangle(fb, Rect)
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: tabcontrol tab color.... [1/2 resolved]

    got it!.....I just had my rect coords off I guess
    thanks
    for your help
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: tabcontrol tab color.... [twice resolved]

    I just go it too. The issue I seen was that the code needed to be in the DrawItem procedure and not
    the Form_Paint procedure.

    I didnt realize either that you were using OwnerDrawnFixed also.
    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13
    New Member
    Join Date
    Jul 2008
    Posts
    1

    Re: tabcontrol tab color.... [twice resolved]

    Hi........
    thanks a lot........ur coding really helped me to solve my problem in tabcoltrol.....
    vidyaa..

  14. #14
    New Member
    Join Date
    Feb 2009
    Posts
    1

    Re: tabcontrol tab color.... [twice resolved]

    hai,wat is the way without inherit to paint tab control? im stuck

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

    Re: tabcontrol tab color.... [twice resolved]

    Have a look at this site:
    http://dotnetrix.co.uk/tabcontrol.htm

    It hosts a large number of custom tabcontrols (source code for VB.NET and C#.NET) which do a variety of things including custom drawing it completely, which is probably what you want.
    (It's pretty complicated though, but it's all there in the source code)

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