TabPages - Caption / Text

Heiko

Well-known member
Joined
Feb 10, 2003
Messages
430
Location
Holstein, Germany.
Just for the record, as I have already told the customer that there is no such builtin functionality so his wish wont come for free :)

Is there a way to display the text of a tabpage (formerly known as caption) in a bold font?
Setting the font property of the page will affect all controls on the page, but not its very own text/caption. Am I missing sth ?
 
Youll need to set the DrawMode property to OwnerDrawFixed and draw the text onto the tabs yourself in the DrawItem event. However, the problem with this method is that bold characters are wider than regular characters, and you cant change the widths of the tabs themselves, so bold text wouldnt fit.

You could either append spaces to the Text property of each tab (which would cause the tab to resize itself to fit), or find another way to make the tabs stand out (such as using red font or something).
 
Here is a simple example I just whipped up; youll need to add your own code to only color the ones you want or whatever.
Code:
    Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
        Dim g As Graphics = e.Graphics
        Dim textX, textY As Integer
        Dim textSize As SizeF
        Dim tabText As String = TabControl1.TabPages(e.Index).Text

        textSize = g.MeasureString(tabText, TabControl1.Font)
        textX = e.Bounds.X + (e.Bounds.Width - textSize.ToSize.Width) \ 2
        textY = e.Bounds.Y + (e.Bounds.Height - textSize.ToSize.Height) \ 2

        g.DrawString(TabControl1.TabPages(e.Index).Text, TabControl1.Font, Brushes.Red, textX, textY)
    End Sub
 
Back
Top