Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Just for the record, as I have already told the customer that there is no such builtin functionality so his wish won't 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 ?

.nerd
  • *Experts*
Posted

You'll 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 can't change the widths of the tabs themselves, so bold text wouldn't 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).

  • *Experts*
Posted
Here is a simple example I just whipped up; you'll need to add your own code to only color the ones you want or whatever.
    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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...