Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with custom Tab control

Status
Not open for further replies.

RebeccaLynn

Programmer
Nov 17, 2003
250
US
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(&quot;Choose a color to specify the color of the tabs&quot;), _
Category(&quot;Appearance&quot;)> _
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. :)
 
Rebecca

Without looking too deeply, try moving the mybase events to the first command executed in the ondrawitem and on paint event



Sweep
...if it works dont mess with it
 
Tried that, still no luck, the Tabs do not change color.

Becca

Somtimes, the easy answer is the hardest to find. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top