Tabcontrol

M

Michael Turner

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.
 
S

scorpion53061

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_DrawItem(ByVal sender As Object, ByVal e As
DrawItemEventArgs)
Dim tc As TabControl = CType(sender, TabControl)
Dim tp As TabPage = tc.TabPages(e.index)
Dim strTitle As String = tp.Text
Dim g As Graphics = e.Graphics
Dim theBrush As Brush = New SolidBrush(Me.ForeColor)
Dim sf As StringFormat = New StringFormat()
sf.Alignment = StringAlignment.Center
g.FillRectangle(New SolidBrush(tp.BackColor),e.Bounds)
g.DrawString(strTitle, tc.Font, theBrush, e.Bounds, sf)
End Sub
 
M

Michael Turner

Hi

I just tried that and even tried copying your code and got the following
error,
C:\Documents and Settings\Michael\My Documents\Visual Studio
Projects\WindowsApplication7\Form1.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.
 
H

Herfried K. Wagner [MVP]

Michael Turner said:
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.co.uk/>
-> "Tips" -> "TabControl"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top