Change text in tab control

Posted on 2007-10-17
Last Modified: 2010-04-23
I would like to change the Font size and color of the text on my tab control when I click it.  I have 5 tabs but each looks the same.  How can I change the font of the header when i click.  Thanks

I tried  TabPage1.Font = New Font("Microsoft Sans Serif", 14, FontStyle.Bold) but that does not change the heading font.

Question by:running32
    LVL 96

    Accepted Solution

    What happens if the change the font for the TabControl?


    Author Comment

    found something, thanks

     Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem

            'Firstly we'll define some parameters.
            Dim CurrentTab As TabPage = TabControl1.TabPages(e.Index)
            Dim ItemRect As Rectangle = TabControl1.GetTabRect(e.Index)
            Dim FillBrush As New SolidBrush(Color.Red)
            Dim TextBrush As New SolidBrush(Color.White)
            Dim sf As New StringFormat
            sf.Alignment = StringAlignment.Center
            sf.LineAlignment = StringAlignment.Center

            'If we are currently painting the Selected TabItem we'll
            'change the brush colors and inflate the rectangle.
            If CBool(e.State And DrawItemState.Selected) Then
                FillBrush.Color = Color.White
                TextBrush.Color = Color.Red
                ItemRect.Inflate(2, 2)
            End If

            'Set up rotation for left and right aligned tabs
            If TabControl1.Alignment = TabAlignment.Left Or TabControl1.Alignment = TabAlignment.Right Then
                Dim RotateAngle As Single = 90
                If TabControl1.Alignment = TabAlignment.Left Then RotateAngle = 270
                Dim cp As New PointF(ItemRect.Left + (ItemRect.Width \ 2), ItemRect.Top + (ItemRect.Height \ 2))
                e.Graphics.TranslateTransform(cp.X, cp.Y)
                ItemRect = New Rectangle(-(ItemRect.Height \ 2), -(ItemRect.Width \ 2), ItemRect.Height, ItemRect.Width)
            End If

            'Next we'll paint the TabItem with our Fill Brush
            e.Graphics.FillRectangle(FillBrush, ItemRect)

            'Now draw the text.
            e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, RectangleF.op_Implicit(ItemRect), sf)

            'Reset any Graphics rotation

            'Finally, we should Dispose of our brushes.

        End Sub

    LVL 96

    Expert Comment

    by:Bob Learned
    Very good, grasshopper!!


    Author Comment

    Thanks for being so quick to respond to the question.  I always appreciate your input.
    LVL 69

    Assisted Solution

    by:Éric Moreau

    Author Comment

    Yeap, that's the one.  Thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now