codice:
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
e.Graphics.Clear(Color.FromArgb(49, 49, 49))
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit
Try : For Each T As TabPage In TabPages
T.BackColor = Color.FromArgb(49, 49, 49)
Next : Catch : End Try
Dim headerRect As New Rectangle(New Point(0, 0), New Point(Me.Width, ItemSize.Height))
e.Graphics.DrawLine(New Pen(Color.FromArgb(35, 35, 35)), New Point(0, ItemSize.Height + 1), New Point(Me.Width, ItemSize.Height + 1))
Dim headerColorBlend As New ColorBlend(2)
headerColorBlend.Colors = New Color() {Color.FromArgb(60, 101, 101, 101), Color.FromArgb(49, 49, 49)}
headerColorBlend.Positions = New Single() {0.0, 1.0}
Dim headerBrush As New LinearGradientBrush(headerRect, Color.Black, Color.Black, 90.0F)
headerBrush.InterpolationColors = headerColorBlend
e.Graphics.FillRectangle(headerBrush, headerRect)
For i = 0 To TabCount - 1
Dim x2 As Rectangle = New Rectangle(New Point(GetTabPositionX(i), GetTabRect(i).Location.Y - 2), New Size(GetTabRect(i).Width, GetTabRect(i).Height))
Dim textrectangle As New Rectangle(x2.Location.X, x2.Location.Y, x2.Width, x2.Height)
If i = SelectedIndex Then
e.Graphics.FillRectangle(Brushes.CadetBlue, New Rectangle(New Point(x2.X + 1, x2.Y + x2.Height - 1), New Point(GetTabRect(i).Width - 1, 2)))
e.Graphics.DrawString(TabPages(i).Text, Font, Brushes.Gainsboro, textrectangle, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
e.Graphics.DrawLine(New Pen(Color.FromArgb(49, 49, 49)), New Point(x2.X, x2.Y + x2.Height + 1), New Point(x2.X + x2.Width - 1, x2.Y + x2.Height + 1))
Else
e.Graphics.DrawString(TabPages(i).Text, Font, Brushes.Gray, textrectangle, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
End If
Dim selTabPath As New GraphicsPath
selTabPath = RoundRect(New Rectangle(New Point(GetTabPositionX(i) + 4, GetTabRect(i).Location.Y - 2), New Size(GetTabRect(i).Width - 8, GetTabRect(i).Height - 2)), 2)
If i = _IndexOver Then
'e.Graphics.FillPath(New LinearGradientBrush(x2, Color.FromArgb(25, 200, 200, 200), Color.FromArgb(100, 49, 49, 49), 90.0F), selTabPath)
e.Graphics.DrawPath(New Pen(Color.FromArgb(80, 100, 100, 100)), selTabPath)
End If
Next
End Sub
E questa invece è la funzione che, dato l'indice della TabPage, ritorna la coordinata di X per poter centrare le schede nel controllo: