RebeccaLynn
Programmer
I am trying to create a custom tabcontorl that I can change the color of the tabs with. I can't seem to get it to work, can anyone help?
Option Strict On
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.ComponentModel
Namespace ColorTabBar
Public Class ColorTab
Inherits Windows.Forms.TabControl
Dim myTabRect As Rectangle
Dim m_tabColor As Color = Color.LightGray
<Description("Choose a color to specify the color of the tabs"
, _
Category("Appearance"
> _
Public Property TabColor() As System.Drawing.Color
Get
Return m_tabColor
End Get
Set(ByVal Value As System.Drawing.Color)
m_tabColor = Value
Me.Refresh()
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim g As Graphics = e.Graphics
Dim p As New Pen(TabColor)
Dim b As New SolidBrush(TabColor)
g.DrawRectangle(p, myTabRect)
g.FillRectangle(b, myTabRect)
MyBase.OnPaint(e)
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
Dim g As Graphics = e.Graphics
Dim p As New Pen(Color.Blue)
Dim b As New SolidBrush(Color.Blue)
g.DrawRectangle(p, myTabRect)
g.FillRectangle(b, myTabRect)
MyBase.OnDrawItem(e)
End Sub
Protected Overrides Sub OnControlAdded(ByVal e As System.Windows.Forms.ControlEventArgs)
myTabRect = Me.GetTabRect(0)
End Sub
End Class
End Namespace
Somtimes, the easy answer is the hardest to find.
Option Strict On
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.ComponentModel
Namespace ColorTabBar
Public Class ColorTab
Inherits Windows.Forms.TabControl
Dim myTabRect As Rectangle
Dim m_tabColor As Color = Color.LightGray
<Description("Choose a color to specify the color of the tabs"
Category("Appearance"
Public Property TabColor() As System.Drawing.Color
Get
Return m_tabColor
End Get
Set(ByVal Value As System.Drawing.Color)
m_tabColor = Value
Me.Refresh()
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim g As Graphics = e.Graphics
Dim p As New Pen(TabColor)
Dim b As New SolidBrush(TabColor)
g.DrawRectangle(p, myTabRect)
g.FillRectangle(b, myTabRect)
MyBase.OnPaint(e)
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
Dim g As Graphics = e.Graphics
Dim p As New Pen(Color.Blue)
Dim b As New SolidBrush(Color.Blue)
g.DrawRectangle(p, myTabRect)
g.FillRectangle(b, myTabRect)
MyBase.OnDrawItem(e)
End Sub
Protected Overrides Sub OnControlAdded(ByVal e As System.Windows.Forms.ControlEventArgs)
myTabRect = Me.GetTabRect(0)
End Sub
End Class
End Namespace
Somtimes, the easy answer is the hardest to find.