如何更改标签页页眉的颜色,标签页面上始终可见的文字?
答案 0 :(得分:0)
也许不是最优雅的解决方案但是..将TabControl的DrawMode更改为OwnerDrawFixed并自己处理绘图。查看MSDN以获取示例。
答案 1 :(得分:0)
除了对DrawItem事件进行编码之外,请按照此事件进行操作,以便随时更改标签页文本。
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