Please help - font color

  • Thread starter Thread starter Keni
  • Start date Start date
K

Keni

How do I set the font color of the text on the actual tab
of a tab page? I have tried changing the forecolor. That
only changes the color for the text inside the tab, it
doesn't change the color of the text displayed on the
actual tab. I want to change the color of TabPage1.text,
not the other controls on the tab page
 
You'll have to set the TabControls DrawMode property to OwnerDrawFixed and
draw the text in the TabControls DrawItem procedure.

VB.Net example:

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

Dim r As RectangleF = RectangleF.op_Implicit(e.Bounds)
Dim ItemBrush As New SolidBrush(TabControl1.BackColor)
Dim sf As New StringFormat

sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center

If CBool(e.State And DrawItemState.Selected) Then
e.Graphics.FillRectangle(ItemBrush, e.Bounds)
e.Graphics.DrawString(TabControl1.TabPages(e.Index).Text, _
e.Font, Brushes.Red, r,
sf)
Else
e.Graphics.DrawString(TabControl1.TabPages(e.Index).Text, _
e.Font,
Brushes.Blue, r, sf)
End If

End Sub
 
Thank you so much!!! It works great!! You are my hero!
-----Original Message-----
You'll have to set the TabControls DrawMode property to OwnerDrawFixed and
draw the text in the TabControls DrawItem procedure.

VB.Net example:

Private Sub TabControl1_DrawItem(ByVal sender As Object, _
ByVal e As
System.Windows.Forms.DrawItemEventArgs) _
 
No problem, Glad to help.
Note however, that this method requires quite a bit of work if Windows XP
Visual Styles are in use since you'll also have to pinvoke the various
uxtheme.dll functions to extract the TabItem bitmaps.
 
Back
Top