|
-
Dec 30th, 2008, 12:52 PM
#1
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.
-
Dec 31st, 2008, 07:38 AM
#2
Re: Veritcle Tab Control
Seems to work fine, except that the HotTracking works even when it is False, since you didn't check for that setting before drawing.
Also, it would be awesome if you could implement the scrolling mechanism that a normal TabControl has when there are too many tabs to display, only this time vertical. It probably won't be easy, but I have seen an example of a manual scrolling mechanism in an owner-drawn tabcontrol (horizontal, but would still be useful), I'll see if I can find it again.
-
Dec 31st, 2008, 08:24 AM
#3
Re: Veritcle Tab Control
 Originally Posted by NickThissen
Seems to work fine, except that the HotTracking works even when it is False, since you didn't check for that setting before drawing.
Good catch, it's in the code now.
 Originally Posted by NickThissen
Also, it would be awesome if you could implement the scrolling mechanism that a normal TabControl has when there are too many tabs to display, only this time vertical. It probably won't be easy, but I have seen an example of a manual scrolling mechanism in an owner-drawn tabcontrol (horizontal, but would still be useful), I'll see if I can find it again.
I'll look into, if you see any articles on the subject send em my way or add it in yourself, everyone's free to improve this thing.
-
Jan 1st, 2009, 01:15 PM
#4
Re: Veritcle Tab Control
http://www.codeproject.com/KB/miscct...abcontrol.aspx
This is the example I meant. It even features vertical tab-scrolling (but the tabs are not horizontal, they are like the default vertical tabcontrol).
It is written in C# but that's easy enough to convert to VB I think...
I think the real problem is that his tabcontrol is completely owner-drawn, while yours is 'only' modifying the default tabcontrol. I have not really looked into it yet, but I don't even know if it is possible to stop the behavior it has now: when there are more tabs then it is possible to display, they line up next to eachother (a bit like a multi-row tabcontrol, except vertical). It seems this is just the default behavior and I don't know if it can be overcome easily without creating the tabcontrol from scratch...
-
Jan 24th, 2010, 10:57 AM
#5
Re: Veritcle Tab Control
Whoa! If you set Multiline to False, everything breaks, and even worse, you can't fix it. Try it out and see.
-
Jan 24th, 2010, 07:30 PM
#6
Re: Veritcle Tab Control
Thanks for letting me know minitech, perhaps I'll look into it tomorrow.
In the mean time, instead of using my own Vert Tab control for the app I'm redesigning (which is why I made this VertTab control in the first place) I ended up using ForumAccountant's VS Tab control thing: http://www.vbforums.com/showthread.php?t=580655
Edit: Ok I've "fixed" it by shadowing the Multiline property & making it readonly, I also set it to be hidden from the designer. The code in post #1 has been edited to include this.
Last edited by JuggaloBrotha; Jan 24th, 2010 at 07:41 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|