Visual Basics Tab control color help.

Posts 1–4 of 4 · Page 1 of 1
Visual Basics Tab control color help.
I am new to VB and trying to make my first GUI. Though the Tab control is annoying me, as the default background is grey. I read around and it is not possible to change without using a code.

Code:
Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem

    'Firstly we'll define some parameters.
    Dim CurrentTab As TabPage = TabControl1.TabPages(e.Index)
    Dim ItemRect As Rectangle = TabControl1.GetTabRect(e.Index)
    Dim FillBrush As New SolidBrush(Color.Red)
    Dim TextBrush As New SolidBrush(Color.White)
    Dim sf As New StringFormat
    sf.Alignment = StringAlignment.Center
    sf.LineAlignment = StringAlignment.Center

    'If we are currently painting the Selected TabItem we'll 
    'change the brush colors and inflate the rectangle.
    If CBool(e.State And DrawItemState.Selected) Then
        FillBrush.Color = Color.White
        TextBrush.Color = Color.Red
        ItemRect.Inflate(2, 2)
    End If

    'Set up rotation for left and right aligned tabs
    If TabControl1.Alignment = TabAlignment.Left Or TabControl1.Alignment = TabAlignment.Right Then
        Dim RotateAngle As Single = 90
        If TabControl1.Alignment = TabAlignment.Left Then RotateAngle = 270
        Dim cp As New PointF(ItemRect.Left + (ItemRect.Width \ 2), ItemRect.Top + (ItemRect.Height \ 2))
        e.Graphics.TranslateTransform(cp.X, cp.Y)
        e.Graphics.RotateTransform(RotateAngle)
        ItemRect = New Rectangle(-(ItemRect.Height \ 2), -(ItemRect.Width \ 2), ItemRect.Height, ItemRect.Width)
    End If

    'Next we'll paint the TabItem with our Fill Brush
    e.Graphics.FillRectangle(FillBrush, ItemRect)

    'Now draw the text.
    e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, RectangleF.op_Implicit(ItemRect), sf)

    'Reset any Graphics rotation
    e.Graphics.ResetTransform()

    'Finally, we should Dispose of our brushes.
    FillBrush.Dispose()
    TextBrush.Dispose()

End Sub
I found this code (Credits to Mike Doherty)
This code is what i need, but it hides the images i have. He says on his website, "I'll leave you the challenge of modifying the code to show an image. "

Because, right now this code changes the default grey background to whatever colour you want, but at the sametime hides the Images.

Does anyone know how to show the images and change the background colour?

Thanks in advance.

- Image of Before

- With Mike's code
I asked this too and no one replied

I see you got your source from the same site I did.

I'm not sure about the images, try Googling something like "vb.net ownerdrawfixed show image on tabs".
Quote Originally Posted by Samueldo View Post
I asked this too and no one replied

I see you got your source from the same site I did.

I'm not sure about the images, try Googling something like "vb.net ownerdrawfixed show image on tabs".
Mate i think i found it

Painting Your Own Tabs - Second Edition - CodeProject

Trying out now.

Edit: still doesn't work but does anyone know how to use the above?
Posts 1–4 of 4 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us