473,699 Members | 2,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tabcontrol

Hi Guys

Having problem with the tab control, I need to set the background color to
something different than the standard, I have found code on the web and now
can redraw the tabpage buttons so the are set to the right color, I can
obviously change the tabpage colour but I am left with a grey top edge(Where
there are no buttons) when the background of the form is changed any ideas
on what I can do?

Mike.

Nov 21 '05 #1
9 3455
Set the tab control's DrawMode property to OwnerDrawFixed, and supply an
event handler for the DrawItem event. In that event, Imports the event
arg's
Graphics object, fill the background rectangle (e.Bounds) with the color
of
your choice, and draw the tab's text on top of it.

Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)
Dim tc As TabControl = CType(sender, TabControl)
Dim tp As TabPage = tc.TabPages(e.i ndex)
Dim strTitle As String = tp.Text
Dim g As Graphics = e.Graphics
Dim theBrush As Brush = New SolidBrush(Me.F oreColor)
Dim sf As StringFormat = New StringFormat()
sf.Alignment = StringAlignment .Center
g.FillRectangle (New SolidBrush(tp.B ackColor),e.Bou nds)
g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)
End Sub

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:Oa******** *****@TK2MSFTNG P14.phx.gbl:
Hi Guys

Having problem with the tab control, I need to set the background color
to
something different than the standard, I have found code on the web and
now
can redraw the tabpage buttons so the are set to the right color, I can
obviously change the tabpage colour but I am left with a grey top
edge(Where
there are no buttons) when the background of the form is changed any
ideas
on what I can do?

Mike.


Nov 21 '05 #2
Hi

I just tried that and even tried copying your code and got the following
error,
C:\Documents and Settings\Michae l\My Documents\Visua l Studio
Projects\Window sApplication7\F orm1.vb(106): Overload resolution failed
because no accessible 'DrawString' can be called with these arguments:
'Public Sub DrawString(s As String, font As System.Drawing. Font, brush
As System.Drawing. Brush, layoutRectangle As System.Drawing. RectangleF,
format As System.Drawing. StringFormat)': Value of type
'System.Drawing .Rectangle' cannot be converted to
'System.Drawing .RectangleF'.
'Public Sub DrawString(s As String, font As System.Drawing. Font, brush
As System.Drawing. Brush, point As System.Drawing. PointF, format As
System.Drawing. StringFormat)': Value of type 'System.Drawing .Rectangle'
cannot be converted to 'System.Drawing .PointF'.
'Public Sub DrawString(s As String, font As System.Drawing. Font, brush
As System.Drawing. Brush, x As Single, y As Single)': Value of type
'System.Drawing .Rectangle' cannot be converted to 'Single'.
'Public Sub DrawString(s As String, font As System.Drawing. Font, brush
As System.Drawing. Brush, x As Single, y As Single)': Value of type
'System.Drawing .StringFormat' cannot be converted to 'Single'.

And Ideas?

Mike.
"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:Om******** ******@TK2MSFTN GP12.phx.gbl...
Set the tab control's DrawMode property to OwnerDrawFixed, and supply an
event handler for the DrawItem event. In that event, Imports the event
arg's
Graphics object, fill the background rectangle (e.Bounds) with the color
of
your choice, and draw the tab's text on top of it.

Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)
Dim tc As TabControl = CType(sender, TabControl)
Dim tp As TabPage = tc.TabPages(e.i ndex)
Dim strTitle As String = tp.Text
Dim g As Graphics = e.Graphics
Dim theBrush As Brush = New SolidBrush(Me.F oreColor)
Dim sf As StringFormat = New StringFormat()
sf.Alignment = StringAlignment .Center
g.FillRectangle (New SolidBrush(tp.B ackColor),e.Bou nds)
g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)
End Sub

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:Oa******** *****@TK2MSFTNG P14.phx.gbl:
Hi Guys

Having problem with the tab control, I need to set the background color
to
something different than the standard, I have found code on the web and
now
can redraw the tabpage buttons so the are set to the right color, I can
obviously change the tabpage colour but I am left with a grey top
edge(Where
there are no buttons) when the background of the form is changed any
ideas
on what I can do?

Mike.



Nov 21 '05 #3
Post your code in your form or class exactly as you have it.
"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:un******** ******@TK2MSFTN GP10.phx.gbl:
Hi

I just tried that and even tried copying your code and got the following
error,
C:\Documents and Settings\Michae l\My Documents\Visua l Studio
Projects\Window sApplication7\F orm1.vb(106): Overload resolution failed
because no accessible 'DrawString' can be called with these arguments:
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, layoutRectangle As System.Drawing. RectangleF,
format As System.Drawing. StringFormat)': Value of type
'System.Drawing .Rectangle' cannot be converted to
'System.Drawing .RectangleF'.
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, point As System.Drawing. PointF, format As
System.Drawing. StringFormat)': Value of type 'System.Drawing .Rectangle'
cannot be converted to 'System.Drawing .PointF'.
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, x As Single, y As Single)': Value of type
'System.Drawing .Rectangle' cannot be converted to 'Single'.
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, x As Single, y As Single)': Value of type
'System.Drawing .StringFormat' cannot be converted to 'Single'.

And Ideas?

Mike.
"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:Om******** ******@TK2MSFTN GP12.phx.gbl...
Set the tab control's DrawMode property to OwnerDrawFixed, and supply
an
event handler for the DrawItem event. In that event, Imports the event
arg's
Graphics object, fill the background rectangle (e.Bounds) with the
color
of
your choice, and draw the tab's text on top of it.

Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)
Dim tc As TabControl = CType(sender, TabControl)
Dim tp As TabPage = tc.TabPages(e.i ndex)
Dim strTitle As String = tp.Text
Dim g As Graphics = e.Graphics
Dim theBrush As Brush = New SolidBrush(Me.F oreColor)
Dim sf As StringFormat = New StringFormat()
sf.Alignment = StringAlignment .Center
g.FillRectangle (New SolidBrush(tp.B ackColor),e.Bou nds)
g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)
End Sub

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:Oa******** *****@TK2MSFTNG P14.phx.gbl:
Hi Guys

Having problem with the tab control, I need to set the background
color
to
something different than the standard, I have found code on the web
and
now
can redraw the tabpage buttons so the are set to the right color, I
can
obviously change the tabpage colour but I am left with a grey top
edge(Where
there are no buttons) when the background of the form is changed any
ideas
on what I can do?

Mike.



Nov 21 '05 #4
Here it is,

Public Class Form1

Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents TabControl1 As System.Windows. Forms.TabContro l

Friend WithEvents TabPage1 As System.Windows. Forms.TabPage

Friend WithEvents TabPage2 As System.Windows. Forms.TabPage

Friend WithEvents TabPage3 As System.Windows. Forms.TabPage

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

Me.TabControl1 = New System.Windows. Forms.TabContro l

Me.TabPage1 = New System.Windows. Forms.TabPage

Me.TabPage2 = New System.Windows. Forms.TabPage

Me.TabPage3 = New System.Windows. Forms.TabPage

Me.TabControl1. SuspendLayout()

Me.SuspendLayou t()

'

'TabControl1

'

Me.TabControl1. Controls.Add(Me .TabPage1)

Me.TabControl1. Controls.Add(Me .TabPage2)

Me.TabControl1. Controls.Add(Me .TabPage3)

Me.TabControl1. DrawMode = System.Windows. Forms.TabDrawMo de.OwnerDrawFix ed

Me.TabControl1. Location = New System.Drawing. Point(40, 40)

Me.TabControl1. Name = "TabControl 1"

Me.TabControl1. SelectedIndex = 0

Me.TabControl1. Size = New System.Drawing. Size(328, 176)

Me.TabControl1. TabIndex = 0

'

'TabPage1

'

Me.TabPage1.Bac kColor = System.Drawing. SystemColors.Ac tiveCaption

Me.TabPage1.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage1.Nam e = "TabPage1"

Me.TabPage1.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage1.Tab Index = 0

Me.TabPage1.Tex t = "TabPage1"

'

'TabPage2

'

Me.TabPage2.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage2.Nam e = "TabPage2"

Me.TabPage2.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage2.Tab Index = 1

Me.TabPage2.Tex t = "TabPage2"

'

'TabPage3

'

Me.TabPage3.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage3.Nam e = "TabPage3"

Me.TabPage3.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage3.Tab Index = 2

Me.TabPage3.Tex t = "TabPage3"

'

'Form1

'

Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

Me.BackColor = System.Drawing. SystemColors.Co ntrolDark

Me.ClientSize = New System.Drawing. Size(528, 437)

Me.Controls.Add (Me.TabControl1 )

Me.Name = "Form1"

Me.Text = "Form1"

Me.TabControl1. ResumeLayout(Fa lse)

Me.ResumeLayout (False)

End Sub

#End Region

Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)

Dim tc As TabControl = CType(sender, TabControl)

Dim tp As TabPage = tc.TabPages(e.i ndex)

Dim strTitle As String = tp.Text

Dim g As Graphics = e.Graphics

Dim theBrush As Brush = New SolidBrush(Me.F oreColor)

Dim sf As StringFormat = New StringFormat

sf.Alignment = StringAlignment .Center

g.FillRectangle (New SolidBrush(tp.B ackColor), e.Bounds)

g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)

End Sub

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s)
Handles MyBase.Load

Me.TabControl1. DrawMode = TabDrawMode.Own erDrawFixed

End Sub

End Class


"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:eg******** ******@TK2MSFTN GP12.phx.gbl...
Post your code in your form or class exactly as you have it.
"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:un******** ******@TK2MSFTN GP10.phx.gbl:
Hi

I just tried that and even tried copying your code and got the following
error,
C:\Documents and Settings\Michae l\My Documents\Visua l Studio
Projects\Window sApplication7\F orm1.vb(106): Overload resolution failed
because no accessible 'DrawString' can be called with these arguments:
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, layoutRectangle As System.Drawing. RectangleF,
format As System.Drawing. StringFormat)': Value of type
'System.Drawing .Rectangle' cannot be converted to
'System.Drawing .RectangleF'.
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, point As System.Drawing. PointF, format As
System.Drawing. StringFormat)': Value of type 'System.Drawing .Rectangle'
cannot be converted to 'System.Drawing .PointF'.
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, x As Single, y As Single)': Value of type
'System.Drawing .Rectangle' cannot be converted to 'Single'.
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, x As Single, y As Single)': Value of type
'System.Drawing .StringFormat' cannot be converted to 'Single'.

And Ideas?

Mike.
"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:Om******** ******@TK2MSFTN GP12.phx.gbl...
Set the tab control's DrawMode property to OwnerDrawFixed, and supply
an
event handler for the DrawItem event. In that event, Imports the event
arg's
Graphics object, fill the background rectangle (e.Bounds) with the
color
of
your choice, and draw the tab's text on top of it.

Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)
Dim tc As TabControl = CType(sender, TabControl)
Dim tp As TabPage = tc.TabPages(e.i ndex)
Dim strTitle As String = tp.Text
Dim g As Graphics = e.Graphics
Dim theBrush As Brush = New SolidBrush(Me.F oreColor)
Dim sf As StringFormat = New StringFormat()
sf.Alignment = StringAlignment .Center
g.FillRectangle (New SolidBrush(tp.B ackColor),e.Bou nds)
g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)
End Sub

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:Oa******** *****@TK2MSFTNG P14.phx.gbl:
> Hi Guys
>
> Having problem with the tab control, I need to set the background
> color
> to
> something different than the standard, I have found code on the web
> and
> now
> can redraw the tabpage buttons so the are set to the right color, I
> can
> obviously change the tabpage colour but I am left with a grey top
> edge(Where
> there are no buttons) when the background of the form is changed any
> ideas
> on what I can do?
>
> Mike.



Nov 21 '05 #5
Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)

Dim tc As TabControl = CType(sender, TabControl)

Dim tp As TabPage = tc.TabPages(e.i ndex)

Dim strTitle As String = tp.Text

Dim g As Graphics = e.Graphics

Dim theBrush As Brush = New SolidBrush(Me.F oreColor)

Dim sf As StringFormat = New StringFormat

sf.Alignment = StringAlignment .Center

g.FillRectangle (New SolidBrush(tp.B ackColor), e.Bounds)
e.Graphics.Draw String(strTitle , e.Font, _
New SolidBrush(e.Fo reColor), Bounds.Left + _
Me.Width, Bounds.Top)
End Sub

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:er******** ******@TK2MSFTN GP10.phx.gbl:
Here it is,

Public Class Form1

Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents TabControl1 As System.Windows. Forms.TabContro l

Friend WithEvents TabPage1 As System.Windows. Forms.TabPage

Friend WithEvents TabPage2 As System.Windows. Forms.TabPage

Friend WithEvents TabPage3 As System.Windows. Forms.TabPage

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

Me.TabControl1 = New System.Windows. Forms.TabContro l

Me.TabPage1 = New System.Windows. Forms.TabPage

Me.TabPage2 = New System.Windows. Forms.TabPage

Me.TabPage3 = New System.Windows. Forms.TabPage

Me.TabControl1. SuspendLayout()

Me.SuspendLayou t()

'

'TabControl1

'

Me.TabControl1. Controls.Add(Me .TabPage1)

Me.TabControl1. Controls.Add(Me .TabPage2)

Me.TabControl1. Controls.Add(Me .TabPage3)

Me.TabControl1. DrawMode =
System.Windows. Forms.TabDrawMo de.OwnerDrawFix ed

Me.TabControl1. Location = New System.Drawing. Point(40, 40)

Me.TabControl1. Name = "TabControl 1"

Me.TabControl1. SelectedIndex = 0

Me.TabControl1. Size = New System.Drawing. Size(328, 176)

Me.TabControl1. TabIndex = 0

'

'TabPage1

'

Me.TabPage1.Bac kColor = System.Drawing. SystemColors.Ac tiveCaption

Me.TabPage1.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage1.Nam e = "TabPage1"

Me.TabPage1.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage1.Tab Index = 0

Me.TabPage1.Tex t = "TabPage1"

'

'TabPage2

'

Me.TabPage2.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage2.Nam e = "TabPage2"

Me.TabPage2.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage2.Tab Index = 1

Me.TabPage2.Tex t = "TabPage2"

'

'TabPage3

'

Me.TabPage3.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage3.Nam e = "TabPage3"

Me.TabPage3.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage3.Tab Index = 2

Me.TabPage3.Tex t = "TabPage3"

'

'Form1

'

Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

Me.BackColor = System.Drawing. SystemColors.Co ntrolDark

Me.ClientSize = New System.Drawing. Size(528, 437)

Me.Controls.Add (Me.TabControl1 )

Me.Name = "Form1"

Me.Text = "Form1"

Me.TabControl1. ResumeLayout(Fa lse)

Me.ResumeLayout (False)

End Sub

#End Region

Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)

Dim tc As TabControl = CType(sender, TabControl)

Dim tp As TabPage = tc.TabPages(e.i ndex)

Dim strTitle As String = tp.Text

Dim g As Graphics = e.Graphics

Dim theBrush As Brush = New SolidBrush(Me.F oreColor)

Dim sf As StringFormat = New StringFormat

sf.Alignment = StringAlignment .Center

g.FillRectangle (New SolidBrush(tp.B ackColor), e.Bounds)

g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)

End Sub

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s)
Handles MyBase.Load

Me.TabControl1. DrawMode = TabDrawMode.Own erDrawFixed

End Sub

End Class


"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:eg******** ******@TK2MSFTN GP12.phx.gbl...
Post your code in your form or class exactly as you have it.
"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:un******** ******@TK2MSFTN GP10.phx.gbl:
Hi

I just tried that and even tried copying your code and got the
following
error,
C:\Documents and Settings\Michae l\My Documents\Visua l Studio
Projects\Window sApplication7\F orm1.vb(106): Overload resolution
failed
because no accessible 'DrawString' can be called with these
arguments:
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, layoutRectangle As
System.Drawing. RectangleF,
format As System.Drawing. StringFormat)': Value of type
'System.Drawing .Rectangle' cannot be converted to
'System.Drawing .RectangleF'.
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, point As System.Drawing. PointF, format As
System.Drawing. StringFormat)': Value of type
'System.Drawing .Rectangle'
cannot be converted to 'System.Drawing .PointF'.
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, x As Single, y As Single)': Value of type
'System.Drawing .Rectangle' cannot be converted to 'Single'.
'Public Sub DrawString(s As String, font As System.Drawing. Font,
brush
As System.Drawing. Brush, x As Single, y As Single)': Value of type
'System.Drawing .StringFormat' cannot be converted to 'Single'.

And Ideas?

Mike.
"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:Om******** ******@TK2MSFTN GP12.phx.gbl...
> Set the tab control's DrawMode property to OwnerDrawFixed, and
> supply
> an
> event handler for the DrawItem event. In that event, Imports the
> event
> arg's
> Graphics object, fill the background rectangle (e.Bounds) with the
> color
> of
> your choice, and draw the tab's text on top of it.
>
> Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e
> As
> DrawItemEventAr gs)
> Dim tc As TabControl = CType(sender, TabControl)
> Dim tp As TabPage = tc.TabPages(e.i ndex)
> Dim strTitle As String = tp.Text
> Dim g As Graphics = e.Graphics
> Dim theBrush As Brush = New SolidBrush(Me.F oreColor)
> Dim sf As StringFormat = New StringFormat()
> sf.Alignment = StringAlignment .Center
> g.FillRectangle (New SolidBrush(tp.B ackColor),e.Bou nds)
> g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)
> End Sub
>
> "Michael Turner" <fi*****@m-turner.co.uk> wrote in message
> news:Oa******** *****@TK2MSFTNG P14.phx.gbl:
> > Hi Guys
> >
> > Having problem with the tab control, I need to set the
> > background
> > color
> > to
> > something different than the standard, I have found code on the
> > web
> > and
> > now
> > can redraw the tabpage buttons so the are set to the right color,
> > I
> > can
> > obviously change the tabpage colour but I am left with a grey
> > top
> > edge(Where
> > there are no buttons) when the background of the form is changed
> > any
> > ideas
> > on what I can do?
> >
> > Mike.
>
>



Nov 21 '05 #6
Hi

I copied and pasted this code into my new project and nothing seems to
happen(yes I did remove the old code), any idea's I must be missing
something? Do you have a sample you have already created I could purhaps
look at?

Mike.

"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:u8******** ******@TK2MSFTN GP15.phx.gbl...
Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)

Dim tc As TabControl = CType(sender, TabControl)

Dim tp As TabPage = tc.TabPages(e.i ndex)

Dim strTitle As String = tp.Text

Dim g As Graphics = e.Graphics

Dim theBrush As Brush = New SolidBrush(Me.F oreColor)

Dim sf As StringFormat = New StringFormat

sf.Alignment = StringAlignment .Center

g.FillRectangle (New SolidBrush(tp.B ackColor), e.Bounds)
e.Graphics.Draw String(strTitle , e.Font, _
New SolidBrush(e.Fo reColor), Bounds.Left + _
Me.Width, Bounds.Top)
End Sub

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:er******** ******@TK2MSFTN GP10.phx.gbl:
Here it is,

Public Class Form1

Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents TabControl1 As System.Windows. Forms.TabContro l

Friend WithEvents TabPage1 As System.Windows. Forms.TabPage

Friend WithEvents TabPage2 As System.Windows. Forms.TabPage

Friend WithEvents TabPage3 As System.Windows. Forms.TabPage

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

Me.TabControl1 = New System.Windows. Forms.TabContro l

Me.TabPage1 = New System.Windows. Forms.TabPage

Me.TabPage2 = New System.Windows. Forms.TabPage

Me.TabPage3 = New System.Windows. Forms.TabPage

Me.TabControl1. SuspendLayout()

Me.SuspendLayou t()

'

'TabControl1

'

Me.TabControl1. Controls.Add(Me .TabPage1)

Me.TabControl1. Controls.Add(Me .TabPage2)

Me.TabControl1. Controls.Add(Me .TabPage3)

Me.TabControl1. DrawMode =
System.Windows. Forms.TabDrawMo de.OwnerDrawFix ed

Me.TabControl1. Location = New System.Drawing. Point(40, 40)

Me.TabControl1. Name = "TabControl 1"

Me.TabControl1. SelectedIndex = 0

Me.TabControl1. Size = New System.Drawing. Size(328, 176)

Me.TabControl1. TabIndex = 0

'

'TabPage1

'

Me.TabPage1.Bac kColor = System.Drawing. SystemColors.Ac tiveCaption

Me.TabPage1.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage1.Nam e = "TabPage1"

Me.TabPage1.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage1.Tab Index = 0

Me.TabPage1.Tex t = "TabPage1"

'

'TabPage2

'

Me.TabPage2.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage2.Nam e = "TabPage2"

Me.TabPage2.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage2.Tab Index = 1

Me.TabPage2.Tex t = "TabPage2"

'

'TabPage3

'

Me.TabPage3.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage3.Nam e = "TabPage3"

Me.TabPage3.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage3.Tab Index = 2

Me.TabPage3.Tex t = "TabPage3"

'

'Form1

'

Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

Me.BackColor = System.Drawing. SystemColors.Co ntrolDark

Me.ClientSize = New System.Drawing. Size(528, 437)

Me.Controls.Add (Me.TabControl1 )

Me.Name = "Form1"

Me.Text = "Form1"

Me.TabControl1. ResumeLayout(Fa lse)

Me.ResumeLayout (False)

End Sub

#End Region

Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)

Dim tc As TabControl = CType(sender, TabControl)

Dim tp As TabPage = tc.TabPages(e.i ndex)

Dim strTitle As String = tp.Text

Dim g As Graphics = e.Graphics

Dim theBrush As Brush = New SolidBrush(Me.F oreColor)

Dim sf As StringFormat = New StringFormat

sf.Alignment = StringAlignment .Center

g.FillRectangle (New SolidBrush(tp.B ackColor), e.Bounds)

g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)

End Sub

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s)
Handles MyBase.Load

Me.TabControl1. DrawMode = TabDrawMode.Own erDrawFixed

End Sub

End Class


"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:eg******** ******@TK2MSFTN GP12.phx.gbl...
Post your code in your form or class exactly as you have it.
"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:un******** ******@TK2MSFTN GP10.phx.gbl:
> Hi
>
> I just tried that and even tried copying your code and got the
> following
> error,
> C:\Documents and Settings\Michae l\My Documents\Visua l Studio
> Projects\Window sApplication7\F orm1.vb(106): Overload resolution
> failed
> because no accessible 'DrawString' can be called with these
> arguments:
> 'Public Sub DrawString(s As String, font As System.Drawing. Font,
> brush
> As System.Drawing. Brush, layoutRectangle As
> System.Drawing. RectangleF,
> format As System.Drawing. StringFormat)': Value of type
> 'System.Drawing .Rectangle' cannot be converted to
> 'System.Drawing .RectangleF'.
> 'Public Sub DrawString(s As String, font As System.Drawing. Font,
> brush
> As System.Drawing. Brush, point As System.Drawing. PointF, format As
> System.Drawing. StringFormat)': Value of type
> 'System.Drawing .Rectangle'
> cannot be converted to 'System.Drawing .PointF'.
> 'Public Sub DrawString(s As String, font As System.Drawing. Font,
> brush
> As System.Drawing. Brush, x As Single, y As Single)': Value of type
> 'System.Drawing .Rectangle' cannot be converted to 'Single'.
> 'Public Sub DrawString(s As String, font As System.Drawing. Font,
> brush
> As System.Drawing. Brush, x As Single, y As Single)': Value of type
> 'System.Drawing .StringFormat' cannot be converted to 'Single'.
>
> And Ideas?
>
> Mike.
>
>
> "scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
> news:Om******** ******@TK2MSFTN GP12.phx.gbl...
> > Set the tab control's DrawMode property to OwnerDrawFixed, and
> > supply
> > an
> > event handler for the DrawItem event. In that event, Imports the
> > event
> > arg's
> > Graphics object, fill the background rectangle (e.Bounds) with the
> > color
> > of
> > your choice, and draw the tab's text on top of it.
> >
> > Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e
> > As
> > DrawItemEventAr gs)
> > Dim tc As TabControl = CType(sender, TabControl)
> > Dim tp As TabPage = tc.TabPages(e.i ndex)
> > Dim strTitle As String = tp.Text
> > Dim g As Graphics = e.Graphics
> > Dim theBrush As Brush = New SolidBrush(Me.F oreColor)
> > Dim sf As StringFormat = New StringFormat()
> > sf.Alignment = StringAlignment .Center
> > g.FillRectangle (New SolidBrush(tp.B ackColor),e.Bou nds)
> > g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)
> > End Sub
> >
> > "Michael Turner" <fi*****@m-turner.co.uk> wrote in message
> > news:Oa******** *****@TK2MSFTNG P14.phx.gbl:
> > > Hi Guys
> > >
> > > Having problem with the tab control, I need to set the
> > > background
> > > color
> > > to
> > > something different than the standard, I have found code on the
> > > web
> > > and
> > > now
> > > can redraw the tabpage buttons so the are set to the right color, > > > I
> > > can
> > > obviously change the tabpage colour but I am left with a grey
> > > top
> > > edge(Where
> > > there are no buttons) when the background of the form is changed
> > > any
> > > ideas
> > > on what I can do?
> > >
> > > Mike.
> >
> >



Nov 21 '05 #7
http://www.onteorasoftware.com/downl...tabcontrol.zip
"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:u4******** ******@TK2MSFTN GP09.phx.gbl:
Hi

I copied and pasted this code into my new project and nothing seems to
happen(yes I did remove the old code), any idea's I must be missing
something? Do you have a sample you have already created I could purhaps
look at?

Mike.

"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:u8******** ******@TK2MSFTN GP15.phx.gbl...
Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)

Dim tc As TabControl = CType(sender, TabControl)

Dim tp As TabPage = tc.TabPages(e.i ndex)

Dim strTitle As String = tp.Text

Dim g As Graphics = e.Graphics

Dim theBrush As Brush = New SolidBrush(Me.F oreColor)

Dim sf As StringFormat = New StringFormat

sf.Alignment = StringAlignment .Center

g.FillRectangle (New SolidBrush(tp.B ackColor), e.Bounds)
e.Graphics.Draw String(strTitle , e.Font, _
New SolidBrush(e.Fo reColor), Bounds.Left + _
Me.Width, Bounds.Top)
End Sub

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:er******** ******@TK2MSFTN GP10.phx.gbl:
Here it is,

Public Class Form1

Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents TabControl1 As System.Windows. Forms.TabContro l

Friend WithEvents TabPage1 As System.Windows. Forms.TabPage

Friend WithEvents TabPage2 As System.Windows. Forms.TabPage

Friend WithEvents TabPage3 As System.Windows. Forms.TabPage

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

Me.TabControl1 = New System.Windows. Forms.TabContro l

Me.TabPage1 = New System.Windows. Forms.TabPage

Me.TabPage2 = New System.Windows. Forms.TabPage

Me.TabPage3 = New System.Windows. Forms.TabPage

Me.TabControl1. SuspendLayout()

Me.SuspendLayou t()

'

'TabControl1

'

Me.TabControl1. Controls.Add(Me .TabPage1)

Me.TabControl1. Controls.Add(Me .TabPage2)

Me.TabControl1. Controls.Add(Me .TabPage3)

Me.TabControl1. DrawMode =
System.Windows. Forms.TabDrawMo de.OwnerDrawFix ed

Me.TabControl1. Location = New System.Drawing. Point(40, 40)

Me.TabControl1. Name = "TabControl 1"

Me.TabControl1. SelectedIndex = 0

Me.TabControl1. Size = New System.Drawing. Size(328, 176)

Me.TabControl1. TabIndex = 0

'

'TabPage1

'

Me.TabPage1.Bac kColor = System.Drawing. SystemColors.Ac tiveCaption

Me.TabPage1.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage1.Nam e = "TabPage1"

Me.TabPage1.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage1.Tab Index = 0

Me.TabPage1.Tex t = "TabPage1"

'

'TabPage2

'

Me.TabPage2.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage2.Nam e = "TabPage2"

Me.TabPage2.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage2.Tab Index = 1

Me.TabPage2.Tex t = "TabPage2"

'

'TabPage3

'

Me.TabPage3.Loc ation = New System.Drawing. Point(4, 22)

Me.TabPage3.Nam e = "TabPage3"

Me.TabPage3.Siz e = New System.Drawing. Size(320, 150)

Me.TabPage3.Tab Index = 2

Me.TabPage3.Tex t = "TabPage3"

'

'Form1

'

Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)

Me.BackColor = System.Drawing. SystemColors.Co ntrolDark

Me.ClientSize = New System.Drawing. Size(528, 437)

Me.Controls.Add (Me.TabControl1 )

Me.Name = "Form1"

Me.Text = "Form1"

Me.TabControl1. ResumeLayout(Fa lse)

Me.ResumeLayout (False)

End Sub

#End Region

Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)

Dim tc As TabControl = CType(sender, TabControl)

Dim tp As TabPage = tc.TabPages(e.i ndex)

Dim strTitle As String = tp.Text

Dim g As Graphics = e.Graphics

Dim theBrush As Brush = New SolidBrush(Me.F oreColor)

Dim sf As StringFormat = New StringFormat

sf.Alignment = StringAlignment .Center

g.FillRectangle (New SolidBrush(tp.B ackColor), e.Bounds)

g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)

End Sub

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s)
Handles MyBase.Load

Me.TabControl1. DrawMode = TabDrawMode.Own erDrawFixed

End Sub

End Class


"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:eg******** ******@TK2MSFTN GP12.phx.gbl...
> Post your code in your form or class exactly as you have it.
>
>
> "Michael Turner" <fi*****@m-turner.co.uk> wrote in message
> news:un******** ******@TK2MSFTN GP10.phx.gbl:
> > Hi
> >
> > I just tried that and even tried copying your code and got the
> > following
> > error,
> > C:\Documents and Settings\Michae l\My Documents\Visua l Studio
> > Projects\Window sApplication7\F orm1.vb(106): Overload resolution
> > failed
> > because no accessible 'DrawString' can be called with these
> > arguments:
> > 'Public Sub DrawString(s As String, font As
> > System.Drawing. Font,
> > brush
> > As System.Drawing. Brush, layoutRectangle As
> > System.Drawing. RectangleF,
> > format As System.Drawing. StringFormat)': Value of type
> > 'System.Drawing .Rectangle' cannot be converted to
> > 'System.Drawing .RectangleF'.
> > 'Public Sub DrawString(s As String, font As
> > System.Drawing. Font,
> > brush
> > As System.Drawing. Brush, point As System.Drawing. PointF, format
> > As
> > System.Drawing. StringFormat)': Value of type
> > 'System.Drawing .Rectangle'
> > cannot be converted to 'System.Drawing .PointF'.
> > 'Public Sub DrawString(s As String, font As
> > System.Drawing. Font,
> > brush
> > As System.Drawing. Brush, x As Single, y As Single)': Value of
> > type
> > 'System.Drawing .Rectangle' cannot be converted to 'Single'.
> > 'Public Sub DrawString(s As String, font As
> > System.Drawing. Font,
> > brush
> > As System.Drawing. Brush, x As Single, y As Single)': Value of
> > type
> > 'System.Drawing .StringFormat' cannot be converted to 'Single'.
> >
> > And Ideas?
> >
> > Mike.
> >
> >
> > "scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in
> > message
> > news:Om******** ******@TK2MSFTN GP12.phx.gbl...
> > > Set the tab control's DrawMode property to OwnerDrawFixed, and
> > > supply
> > > an
> > > event handler for the DrawItem event. In that event, Imports
> > > the
> > > event
> > > arg's
> > > Graphics object, fill the background rectangle (e.Bounds) with
> > > the
> > > color
> > > of
> > > your choice, and draw the tab's text on top of it.
> > >
> > > Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal
> > > e
> > > As
> > > DrawItemEventAr gs)
> > > Dim tc As TabControl = CType(sender, TabControl)
> > > Dim tp As TabPage = tc.TabPages(e.i ndex)
> > > Dim strTitle As String = tp.Text
> > > Dim g As Graphics = e.Graphics
> > > Dim theBrush As Brush = New SolidBrush(Me.F oreColor)
> > > Dim sf As StringFormat = New StringFormat()
> > > sf.Alignment = StringAlignment .Center
> > > g.FillRectangle (New SolidBrush(tp.B ackColor),e.Bou nds)
> > > g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)
> > > End Sub
> > >
> > > "Michael Turner" <fi*****@m-turner.co.uk> wrote in message
> > > news:Oa******** *****@TK2MSFTNG P14.phx.gbl:
> > > > Hi Guys
> > > >
> > > > Having problem with the tab control, I need to set the
> > > > background
> > > > color
> > > > to
> > > > something different than the standard, I have found code on
> > > > the
> > > > web
> > > > and
> > > > now
> > > > can redraw the tabpage buttons so the are set to the right color, > > > > I
> > > > can
> > > > obviously change the tabpage colour but I am left with a
> > > > grey
> > > > top
> > > > edge(Where
> > > > there are no buttons) when the background of the form is
> > > > changed
> > > > any
> > > > ideas
> > > > on what I can do?
> > > >
> > > > Mike.
> > >
> > >
>
>



Nov 21 '05 #8
Thanks for that,

But if you change the forms background colour the area without tabs on is
still grey, any more ideas?

Mike

"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
http://www.onteorasoftware.com/downl...tabcontrol.zip
"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:u4******** ******@TK2MSFTN GP09.phx.gbl:
Hi

I copied and pasted this code into my new project and nothing seems to
happen(yes I did remove the old code), any idea's I must be missing
something? Do you have a sample you have already created I could purhaps
look at?

Mike.

"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
news:u8******** ******@TK2MSFTN GP15.phx.gbl...
Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
DrawItemEventAr gs)

Dim tc As TabControl = CType(sender, TabControl)

Dim tp As TabPage = tc.TabPages(e.i ndex)

Dim strTitle As String = tp.Text

Dim g As Graphics = e.Graphics

Dim theBrush As Brush = New SolidBrush(Me.F oreColor)

Dim sf As StringFormat = New StringFormat

sf.Alignment = StringAlignment .Center

g.FillRectangle (New SolidBrush(tp.B ackColor), e.Bounds)
e.Graphics.Draw String(strTitle , e.Font, _
New SolidBrush(e.Fo reColor), Bounds.Left + _
Me.Width, Bounds.Top)
End Sub

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:er******** ******@TK2MSFTN GP10.phx.gbl:
> Here it is,
>
> Public Class Form1
>
> Inherits System.Windows. Forms.Form
>
> #Region " Windows Form Designer generated code "
>
> Public Sub New()
>
> MyBase.New()
>
> 'This call is required by the Windows Form Designer.
>
> InitializeCompo nent()
>
> 'Add any initialization after the InitializeCompo nent() call
>
> End Sub
>
> 'Form overrides dispose to clean up the component list.
>
> Protected Overloads Overrides Sub Dispose(ByVal disposing As
> Boolean)
>
> If disposing Then
>
> If Not (components Is Nothing) Then
>
> components.Disp ose()
>
> End If
>
> End If
>
> MyBase.Dispose( disposing)
>
> End Sub
>
> 'Required by the Windows Form Designer
>
> Private components As System.Componen tModel.IContain er
>
> 'NOTE: The following procedure is required by the Windows Form
> Designer
>
> 'It can be modified using the Windows Form Designer.
>
> 'Do not modify it using the code editor.
>
> Friend WithEvents TabControl1 As System.Windows. Forms.TabContro l
>
> Friend WithEvents TabPage1 As System.Windows. Forms.TabPage
>
> Friend WithEvents TabPage2 As System.Windows. Forms.TabPage
>
> Friend WithEvents TabPage3 As System.Windows. Forms.TabPage
>
> <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
> InitializeCompo nent()
>
> Me.TabControl1 = New System.Windows. Forms.TabContro l
>
> Me.TabPage1 = New System.Windows. Forms.TabPage
>
> Me.TabPage2 = New System.Windows. Forms.TabPage
>
> Me.TabPage3 = New System.Windows. Forms.TabPage
>
> Me.TabControl1. SuspendLayout()
>
> Me.SuspendLayou t()
>
> '
>
> 'TabControl1
>
> '
>
> Me.TabControl1. Controls.Add(Me .TabPage1)
>
> Me.TabControl1. Controls.Add(Me .TabPage2)
>
> Me.TabControl1. Controls.Add(Me .TabPage3)
>
> Me.TabControl1. DrawMode =
> System.Windows. Forms.TabDrawMo de.OwnerDrawFix ed
>
> Me.TabControl1. Location = New System.Drawing. Point(40, 40)
>
> Me.TabControl1. Name = "TabControl 1"
>
> Me.TabControl1. SelectedIndex = 0
>
> Me.TabControl1. Size = New System.Drawing. Size(328, 176)
>
> Me.TabControl1. TabIndex = 0
>
> '
>
> 'TabPage1
>
> '
>
> Me.TabPage1.Bac kColor = System.Drawing. SystemColors.Ac tiveCaption
>
> Me.TabPage1.Loc ation = New System.Drawing. Point(4, 22)
>
> Me.TabPage1.Nam e = "TabPage1"
>
> Me.TabPage1.Siz e = New System.Drawing. Size(320, 150)
>
> Me.TabPage1.Tab Index = 0
>
> Me.TabPage1.Tex t = "TabPage1"
>
> '
>
> 'TabPage2
>
> '
>
> Me.TabPage2.Loc ation = New System.Drawing. Point(4, 22)
>
> Me.TabPage2.Nam e = "TabPage2"
>
> Me.TabPage2.Siz e = New System.Drawing. Size(320, 150)
>
> Me.TabPage2.Tab Index = 1
>
> Me.TabPage2.Tex t = "TabPage2"
>
> '
>
> 'TabPage3
>
> '
>
> Me.TabPage3.Loc ation = New System.Drawing. Point(4, 22)
>
> Me.TabPage3.Nam e = "TabPage3"
>
> Me.TabPage3.Siz e = New System.Drawing. Size(320, 150)
>
> Me.TabPage3.Tab Index = 2
>
> Me.TabPage3.Tex t = "TabPage3"
>
> '
>
> 'Form1
>
> '
>
> Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
>
> Me.BackColor = System.Drawing. SystemColors.Co ntrolDark
>
> Me.ClientSize = New System.Drawing. Size(528, 437)
>
> Me.Controls.Add (Me.TabControl1 )
>
> Me.Name = "Form1"
>
> Me.Text = "Form1"
>
> Me.TabControl1. ResumeLayout(Fa lse)
>
> Me.ResumeLayout (False)
>
> End Sub
>
> #End Region
>
>
>
>
>
> Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal e As
> DrawItemEventAr gs)
>
> Dim tc As TabControl = CType(sender, TabControl)
>
> Dim tp As TabPage = tc.TabPages(e.i ndex)
>
> Dim strTitle As String = tp.Text
>
> Dim g As Graphics = e.Graphics
>
> Dim theBrush As Brush = New SolidBrush(Me.F oreColor)
>
> Dim sf As StringFormat = New StringFormat
>
> sf.Alignment = StringAlignment .Center
>
> g.FillRectangle (New SolidBrush(tp.B ackColor), e.Bounds)
>
> g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)
>
> End Sub
>
>
>
>
>
> Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
> System.EventArg s)
> Handles MyBase.Load
>
> Me.TabControl1. DrawMode = TabDrawMode.Own erDrawFixed
>
> End Sub
>
> End Class
>
>
>
>
> "scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in message
> news:eg******** ******@TK2MSFTN GP12.phx.gbl...
> > Post your code in your form or class exactly as you have it.
> >
> >
> > "Michael Turner" <fi*****@m-turner.co.uk> wrote in message
> > news:un******** ******@TK2MSFTN GP10.phx.gbl:
> > > Hi
> > >
> > > I just tried that and even tried copying your code and got the
> > > following
> > > error,
> > > C:\Documents and Settings\Michae l\My Documents\Visua l Studio
> > > Projects\Window sApplication7\F orm1.vb(106): Overload resolution
> > > failed
> > > because no accessible 'DrawString' can be called with these
> > > arguments:
> > > 'Public Sub DrawString(s As String, font As
> > > System.Drawing. Font,
> > > brush
> > > As System.Drawing. Brush, layoutRectangle As
> > > System.Drawing. RectangleF,
> > > format As System.Drawing. StringFormat)': Value of type
> > > 'System.Drawing .Rectangle' cannot be converted to
> > > 'System.Drawing .RectangleF'.
> > > 'Public Sub DrawString(s As String, font As
> > > System.Drawing. Font,
> > > brush
> > > As System.Drawing. Brush, point As System.Drawing. PointF, format
> > > As
> > > System.Drawing. StringFormat)': Value of type
> > > 'System.Drawing .Rectangle'
> > > cannot be converted to 'System.Drawing .PointF'.
> > > 'Public Sub DrawString(s As String, font As
> > > System.Drawing. Font,
> > > brush
> > > As System.Drawing. Brush, x As Single, y As Single)': Value of
> > > type
> > > 'System.Drawing .Rectangle' cannot be converted to 'Single'.
> > > 'Public Sub DrawString(s As String, font As
> > > System.Drawing. Font,
> > > brush
> > > As System.Drawing. Brush, x As Single, y As Single)': Value of
> > > type
> > > 'System.Drawing .StringFormat' cannot be converted to 'Single'.
> > >
> > > And Ideas?
> > >
> > > Mike.
> > >
> > >
> > > "scorpion53 061" <ad***@nospamhe rekjmsolutions. com> wrote in
> > > message
> > > news:Om******** ******@TK2MSFTN GP12.phx.gbl...
> > > > Set the tab control's DrawMode property to OwnerDrawFixed, and
> > > > supply
> > > > an
> > > > event handler for the DrawItem event. In that event, Imports
> > > > the
> > > > event
> > > > arg's
> > > > Graphics object, fill the background rectangle (e.Bounds) with
> > > > the
> > > > color
> > > > of
> > > > your choice, and draw the tab's text on top of it.
> > > >
> > > > Private Sub tabControl1_Dra wItem(ByVal sender As Object, ByVal > > > > e
> > > > As
> > > > DrawItemEventAr gs)
> > > > Dim tc As TabControl = CType(sender, TabControl)
> > > > Dim tp As TabPage = tc.TabPages(e.i ndex)
> > > > Dim strTitle As String = tp.Text
> > > > Dim g As Graphics = e.Graphics
> > > > Dim theBrush As Brush = New SolidBrush(Me.F oreColor)
> > > > Dim sf As StringFormat = New StringFormat()
> > > > sf.Alignment = StringAlignment .Center
> > > > g.FillRectangle (New SolidBrush(tp.B ackColor),e.Bou nds)
> > > > g.DrawString(st rTitle, tc.Font, theBrush, e.Bounds, sf)
> > > > End Sub
> > > >
> > > > "Michael Turner" <fi*****@m-turner.co.uk> wrote in message
> > > > news:Oa******** *****@TK2MSFTNG P14.phx.gbl:
> > > > > Hi Guys
> > > > >
> > > > > Having problem with the tab control, I need to set the
> > > > > background
> > > > > color
> > > > > to
> > > > > something different than the standard, I have found code on
> > > > > the
> > > > > web
> > > > > and
> > > > > now
> > > > > can redraw the tabpage buttons so the are set to the right

color,
> > > > > I
> > > > > can
> > > > > obviously change the tabpage colour but I am left with a
> > > > > grey
> > > > > top
> > > > > edge(Where
> > > > > there are no buttons) when the background of the form is
> > > > > changed
> > > > > any
> > > > > ideas
> > > > > on what I can do?
> > > > >
> > > > > Mike.
> > > >
> > > >
> >
> >



Nov 21 '05 #9
"Michael Turner" <fi*****@m-turner.co.uk> schrieb:
Having problem with the tab control, I need to set the
background color to something different than the standard,
I have found code on the web and now can redraw the
tabpage buttons so the are set to the right color, I can
obviously change the tabpage colour but I am left with
a grey top edge(Where there are no buttons) when the
background of the form is changed any ideas
on what I can do?


<URL:http://www.dotnetrix.c o.uk/>
-> "Tips" -> "TabControl "

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
18507
by: Tamir Khason | last post by:
How be able to manage more deeply UI of TabControl and TabPage For example - I want to manage border color, change color of TabPage reef, eliminate spaces from both sides of the reef, so I bould custom control that inherit all information from TabPage, but how to access those properties, not supported by standart interface??? Thank you
2
2364
by: Patrick McGuire | last post by:
I want to place a tabControl with almost identical properties on several forms. I think the best way is to define a UserControl that inherits System.Windows.Forms.TabControl, and place all my controls on it. The problem is that I don't know how to bring up the graphical design interface for the TabControl. I suppose I COULD just design it as a UserControl and place a TabControl on it, but that seems a bit... inelegant (I'm going to...
5
3340
by: Zadkin | last post by:
Does anyone know, if it's possible to set the orientation of the tabpagebuttons to horizontal instead of vertical when the alignment property of my tabcontrol is set to left or right? Thanks in advance Zadkin
2
3350
by: Simon Verona | last post by:
I have a few hundred forms in my application. All are based on a custom base form class. I decided that I wanted to globally change the look and feel of many of the controls in my application - including the tab control. I did this by writing a component that I attached to the form. The component has a "Start" function which takes the form as a paramater. This cycles through all the controls on the form, changes some of the properties...
2
2777
by: Gav | last post by:
I am writing an application where I will have a TabControl and 3 styles of Tabs to go in it, each containing different controls. The tabs will be added to the tabcontrol when items are clicked on in a TreeView. So the the application starts by displaying no tabs and adds them in as required. There could be any number of each tab (0 upwards). What is the best way of me doing this? Should I create 3 custom controls that extend TabPage?...
1
3456
by: =?Utf-8?B?QWxleCBLLg==?= | last post by:
Hi all In a Visual Studio 2005 C# project, I have a simplest tabcontrol with two tabpages. When I set tab control's Alignment property to Right, tab texts (captions) disappear. Does anybody know how to fix this? I tried this on two computers, at work and at home, both with Windows XP with latest service packs, and Framework 2.0 and 3.0 with latest SP.
0
1416
by: bertie78 | last post by:
Hi all, New poster here! I'm having some difficulty updating a tabcontrol cross-threads. The general idea is : the main thread is the owner of the tab control and the form controls. However, due to the vast amount of data to populate listviews within the tabs, I have created a worker thread (an implementation of a BackgroundWorker) to form the data and populate a tabcontrol 'offline', so that it doesn't interfer with (i.e freeze) the UI. ...
2
2113
by: Jamey | last post by:
Ran into an inconvenience with TabControls yesterday. I found a partial explanation from Allen Browne on the MS message boards explaining when it happens, but not why. I thought Stephen Lebans (who's done a little work with this for his multi-colored listbox class), or someone else might've figured this out. Here's the scenario: DBs created on Windows XP using A2K7 are apparently incapable of displaying TabControl transparency....
2
6272
by: Claudia Fong | last post by:
Hi, I added a tabcontrol in a panel in my form. My tabcontrol have more than 3 pages.. each page contains textboxes, combobox, checkbox. I want to disable the items of each of the page of the tabcontrol (so that the user won't be able to change the values in the textboxes, combobox, checkbox) without the tabcontrol turn into grey.
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9187
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7777
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2361
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.