Vb.net (2010) - Tabcontrol Header Color of the TaBPage
I created this utitlity to Change the selected Tabcontrol header to the tabpage's background color. Call this function in the tabcontrols drawitem event like this :
eg: tabheader(sender,e,tabcontrol1). Learn Tabcontrol Header Color of the TaBPage in Vb.net 2010.
Find the steps for Vb.net (2010) - Tabcontrol Header Color of the TaBPage
Just add this function to any of your vb module.
Call this function in the tabcontrols drawitem event like this :
eg: tabheader(sender,e,tabcontrol1)
' Tabcontrol1 is the name of the tabcontrol is this example
Important : Set the DrawMode Property of the TabControl to "OwnerDrawFixed" to invoke the drawitem event
Sub TabHeader(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs, ByVal TabControl1 As Windows.Forms.TabControl)
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)
Dim r1 As Rectangle = e.Bounds
sf.Alignment = StringAlignment.Center
r1.Location = New Point(r1.X + 4, r1.Y)
r1.Size = New Size(r1.Width - 4, r1.Height)
Dim strTitle As String = tp.Text
If TabControl1.SelectedIndex = e.Index Then
br = New SolidBrush(tp.BackColor)
g.FillRectangle(br, r1)
br = New SolidBrush(tp.ForeColor)
g.DrawString(strTitle, TabControl1.Font, br, r, sf)
Else
br = New SolidBrush(Color.WhiteSmoke)
g.FillRectangle(br, r1)
br = New SolidBrush(Color.Black)
g.DrawString(strTitle, TabControl1.Font, br, r, sf)
End If
End Sub