tabcontrol

  • Thread starter Thread starter ahmeddc
  • Start date Start date
A

ahmeddc

Guest
hi

i found this class for tabcontrol

i want to add close button and image

1382949.png

Imports System.Drawing.Drawing2D
Imports System.Drawing.Text

Class FirefoxSubTabControl
Inherits TabControl
Public ReadOnly Property GlobalFont(ByVal B As FontStyle, ByVal S As Integer) As Font
Get
Return New Font("Segoe UI", S, B)
End Get
End Property
Public Sub CenterStringTab(ByVal G As Graphics, ByVal text As String, ByVal font As Font, ByVal brush As Brush, ByVal rect As Rectangle, Optional ByVal shadow As Boolean = False, Optional ByVal yOffset As Integer = 0)

Dim textSize As SizeF = G.MeasureString(text, font)
Dim textX As Integer = rect.X + (rect.Width / 2) - (textSize.Width / 2)
Dim textY As Integer = rect.Y + (rect.Height / 2) - (textSize.Height / 2) + yOffset

If shadow Then G.DrawString(text, font, Brushes.Black, textX + 1, textY + 1)
G.DrawString(text, font, brush, textX, textY + 1)

End Sub
Public Function GreyColor(ByVal G As UInteger) As Color
Return Color.FromArgb(G, G, G)
End Function
#Region " Private "
Private G As Graphics
Private TabRect As Rectangle
#End Region

#Region " Control "

Sub New()
DoubleBuffered = True
Alignment = TabAlignment.Top
End Sub

Protected Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
SetStyle(ControlStyles.UserPaint, True)
ItemSize = New Size(100, 40)
SizeMode = TabSizeMode.Fixed
End Sub

Protected Overrides Sub OnControlAdded(ByVal e As ControlEventArgs)
MyBase.OnControlAdded(e)
Try
For i As Integer = 0 To TabPages.Count - 1
TabPages(i).BackColor = Color.White
TabPages(i).ForeColor = Color.FromArgb(66, 79, 90)
TabPages(i).Font = GlobalFont(FontStyle.Regular, 10)
Next
Catch
End Try
End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

G = e.Graphics
G.SmoothingMode = SmoothingMode.HighQuality
G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit

MyBase.OnPaint(e)

G.Clear(Parent.BackColor)

For i As Integer = 0 To TabPages.Count - 1

TabRect = GetTabRect(i)

If GetTabRect(i).Contains(Me.PointToClient(Cursor.Position)) And Not SelectedIndex = i Then

Using B As New SolidBrush(GreyColor(240))
G.FillRectangle(B, New Rectangle(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2, GetTabRect(i).Width, GetTabRect(i).Height + 1))
End Using

ElseIf SelectedIndex = i Then

Using B As New SolidBrush(GreyColor(240))
G.FillRectangle(B, New Rectangle(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2, GetTabRect(i).Width, GetTabRect(i).Height + 1))
End Using

Using P As New Pen(Color.FromArgb(255, 149, 0), 4)
G.DrawLine(P, New Point(TabRect.X - 2, TabRect.Y + ItemSize.Height - 2), New Point(TabRect.X + TabRect.Width - 2, TabRect.Y + ItemSize.Height - 2))
End Using

ElseIf Not SelectedIndex = i Then
G.FillRectangle(Brushes.White, GetTabRect(i))
End If

Using B As New SolidBrush(Color.FromArgb(56, 69, 80))
CenterStringTab(G, TabPages(i).Text, GlobalFont(FontStyle.Regular, 10), B, GetTabRect(i))
End Using

Next

Using P As New Pen(GreyColor(200))
G.DrawLine(P, New Point(0, ItemSize.Height + 2), New Point(Width, ItemSize.Height + 2))
End Using

End Sub



#End Region

End Class

Continue reading...
 
Back
Top