Option Explicit On
Option Strict On
Option Infer Off
Imports System.ComponentModel
Public Class VertTabControl
Inherits System.Windows.Forms.TabControl
Private _TabSize As Size
Private _HotIndex As Integer = -1I
Private _HotColor As Color = Color.Blue
Public Sub New()
MyBase.Alignment = TabAlignment.Left
MyBase.DrawMode = TabDrawMode.OwnerDrawFixed
MyBase.SizeMode = TabSizeMode.Fixed
MyBase.ItemSize = New Size(23I, 73I)
Me._TabSize = New Size(73I, 23I)
End Sub
#Region " Properties "
<Browsable(False), EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), _
DefaultValue(False)> _
Public Shadows ReadOnly Property ItemSize() As Size
Get
Return MyBase.ItemSize
End Get
End Property
<Browsable(False), EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), _
DefaultValue(False)> _
Public Shadows ReadOnly Property DrawMode() As TabDrawMode
Get
Return TabDrawMode.OwnerDrawFixed
End Get
End Property
<Browsable(False), EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), _
DefaultValue(False)> _
Public Shadows ReadOnly Property Alignment() As TabAlignment
Get
Return TabAlignment.Left
End Get
End Property
<Browsable(False), EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), _
DefaultValue(False)> _
Public Shadows ReadOnly Property SizeMode() As TabSizeMode
Get
Return TabSizeMode.Fixed
End Get
End Property
<Description("Color of the tab text when mouse hovers over it"), DefaultValue("Blue"), Category("Appearance")> _
Public Property HotTrackColor() As Color
Get
Return Me._HotColor
End Get
Set(ByVal value As Color)
If Me._HotColor.Equals(value) = False Then Me._HotColor = value
End Set
End Property
<Description("The size of the tabs"), DefaultValue("73, 23"), Category("Appearance")> _
Public Property TabSize() As Size
Get
Return Me._TabSize
End Get
Set(ByVal value As Size)
If Me._TabSize <> value Then
Me._TabSize = value
MyBase.ItemSize = New Size(Me._TabSize.Height, Me._TabSize.Width)
End If
End Set
End Property
#End Region
#Region " Handled Items "
Private Sub VertTabControl_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Me.DrawItem
e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds)
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
If e.Index = Me._HotIndex Then
e.Graphics.DrawString(Me.TabPages(e.Index).Text, Me.Font, New SolidBrush(_HotColor), RectangleF.op_Implicit(e.Bounds), sf)
Else
e.Graphics.DrawString(Me.TabPages(e.Index).Text, Me.Font, SystemBrushes.ControlText, RectangleF.op_Implicit(e.Bounds), sf)
End If
End Sub
Private Sub VertTabControl_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
If Me._HotIndex <> -1I Then
Me.Invalidate(Me.GetTabRect(Me._HotIndex))
Me._HotIndex = -1I
End If
End Sub
Private Sub VertTabControl_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
For i As Integer = 0I To Me.TabCount - 1I
If i <> Me._HotIndex Then
If Me.GetTabRect(i).Contains(e.Location) Then
If Me._HotIndex <> -1I Then Me.Invalidate(Me.GetTabRect(Me._HotIndex))
Me._HotIndex = i
Me.Invalidate(Me.GetTabRect(Me._HotIndex))
Exit For
End If
End If
Next i
End Sub
#End Region
End Class