Winform vb.net - how to change color of Tab?
How can I change the color of the Tab Page Header, the text that appears on the 开发者_如何学Gopart of the Tab that is always visible?
Maybe not the most elegant solution but.. Change the DrawMode of the TabControl to OwnerDrawFixed and handle the drawing yourself. Check MSDN for examples.
In addition to coding the DrawItem Event, followup with this event to change the tabpage text whenever you want to.
Private Sub ChangeTabPageTextColor(ByVal TabPageIndex As Integer, ByVal ForeColor As Color)
' Get the area of the header of this TabPage
Dim HeaderRect As Rectangle = TabControl1.GetTabRect(TabPageIndex)
' Identify which TabPage is currently selected
Dim SelectedTab As TabPage = TabControl1.TabPages(TabPageIndex)
' Create a Brush to paint the Text
Dim TextBrush As New SolidBrush(ForeColor)
' Declare the text alignment variable
Dim sf As New StringFormat()
' Set the Horizontal Alignment of the Text
sf.Alignment = StringAlignment.Center
' Set the Verticle Alignment of the Text
sf.LineAlignment = StringAlignment.Near
' Declare a Font
Dim newfont As New Font(TabControl1.Font.Name, TabControl1.Font.Size, FontStyle.Regular)
' Draw the text
TabControl1.CreateGraphics().DrawString(SelectedTab.Text, newfont, TextBrush, HeaderRect, sf)
' Job done - dispose of the Brush
TextBrush.Dispose()
End Sub
精彩评论