1
如何更改選項卡頁眉的顏色,該選項卡上出現的文字始終可見?Winform vb.net - 如何更改Tab的顏色?
如何更改選項卡頁眉的顏色,該選項卡上出現的文字始終可見?Winform vb.net - 如何更改Tab的顏色?
也許不是最優雅的解決方案,但..將TabControl的DrawMode更改爲OwnerDrawFixed並自己處理繪圖。以MSDN爲例。
除了對DrawItem事件進行編碼之外,還可以通過此事件隨時更改Tabpage文本。
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
太不雅觀加上需要處理所有其他標籤及其文本。我想要做的只是改變一個標籤頁眉的顏色。 – Alex 2010-02-17 01:55:02