2011-12-07 100 views
2

如何將灰色部分更改爲白色? 我希望我的tabcontrol充滿全白色。如何更改選項卡控件背景色(VB.NET)

enter image description here

到目前爲止我所做的是這樣的:

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 tp As TabPage = TabControl1.TabPages(e.Index) 
    Dim br As Brush 
    Dim sf As New StringFormat 

    Dim r As New RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2) 

    sf.Alignment = StringAlignment.Center 

    Dim strTitle As String = tp.Text 

    'If the current index is the Selected Index, change the color 
    If TabControl1.SelectedIndex = e.Index Then 

     'this is the background color of the tabpage header 
     br = New SolidBrush(Color.White) ' chnge to your choice 
     g.FillRectangle(br, e.Bounds) 

     'this is the foreground color of the text in the tab header 
     br = New SolidBrush(Color.Black) ' change to your choice 
     g.DrawString(strTitle, TabControl1.Font, br, r, sf) 

    Else 

     'these are the colors for the unselected tab pages 
     br = New SolidBrush(Color.White) ' Change this to your preference 
     g.FillRectangle(br, e.Bounds) 
     br = New SolidBrush(Color.Black) 
     g.DrawString(strTitle, TabControl1.Font, br, r, sf) 

    End If 
End Sub 

,我也把這個在pageLoad的功能:

TabControl1.DrawMode = TabDrawMode.OwnerDrawFixed 
For Each tg As TabPage In TabControl1.TabPages 
    tg.BackColor = Color.White 
Next 

回答

0

花費公平的時間來研究,如果有人找到解決辦法;可能會有一些解決辦法。但根據MSDN Ref

TabControl.BackColor物業

NET框架(當前版本)此API支持產品 基礎結構,不適合直接在代碼中使用。

此成員對此控件無意義。

命名空間:System.Windows.Forms程序集:System.Windows.Forms的(在 System.Windows.Forms.dll中)

據我瞭解,這是從用戶的Windows設置來調節。 (Highlight ColorTabControl,表格和其他控件;否則MS可以簡單地打開這個屬性。

相關問題