Results 1 to 6 of 6

Thread: Vertical Tab Control

Threaded View

  1. #1

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Vertical Tab Control

    Code:
    Option Explicit On
    Option Strict On
    Option Infer Off
    
    Imports System.ComponentModel
    
    <System.Diagnostics.DebuggerStepThrough()> _
    Public Class VertTabControl
        Inherits System.Windows.Forms.TabControl
    
    #Region " Variables "
        Private _TabSize As Size
    
        Private _HotIndex As Integer = -1I
        Private _HotColor As Color = Color.Blue
    
        Private _HotBrush As SolidBrush
    #End Region
    #Region " Constructors "
        Public Sub New()
            MyBase.Alignment = TabAlignment.Left
            MyBase.DrawMode = TabDrawMode.OwnerDrawFixed
            MyBase.SizeMode = TabSizeMode.Fixed
            MyBase.ItemSize = New Size(23I, 73I)
            MyBase.HotTrack = True
            MyBase.Multiline = True
            Me._TabSize = New Size(73I, 23I)
            Me._HotBrush = New SolidBrush(_HotColor)
        End Sub
    #End Region
    #Region " Properties "
        <Browsable(False), EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), _
        DefaultValue(True)> _
        Public Shadows ReadOnly Property Multiline() As Boolean
            Get
                Return MyBase.Multiline
            End Get
        End Property
    
        <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._HotBrush.Dispose()
                    Me._HotColor = value
                    Me._HotBrush = New SolidBrush(value)
                End If
            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_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
            Me._HotBrush.Dispose()
        End Sub
    
        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 Me.HotTrack = True AndAlso e.Index = Me._HotIndex Then
                e.Graphics.DrawString(Me.TabPages(e.Index).Text, Me.Font, Me._HotBrush, 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
            sf.Dispose()
        End Sub
    
        Private Sub VertTabControl_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
            If Me.HotTrack = True AndAlso 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
            If Me.HotTrack = True Then
                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 If
        End Sub
    
    #End Region
    
    End Class
    To use it in VS 2005 simply comment the 'Option Infer Off' line out and you're set.
    Last edited by JuggaloBrotha; Jun 22nd, 2010 at 12:10 PM.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width