TabPage Color

Hi,

I need to change the backcolor of a TabControl (not the individual TabPages). How should I do this? Any code/links appreciated!

Edit: More specifically, I just want to change the colour behind the TabPage Tabs, so it doesn't look awkward after Ive changed the color of the TabPages themselves.
LVL 3
eekjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LacutahCommented:
1.  On the TabControl object, set the property "DrawMode" to "OwnerDrawFixed"
2.  Handle the TabControl's "DrawItem" event, here's an example that draws a black background (remember, you'll have to also draw the text!)
    Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
        'This draws the background.
        e.Graphics.FillRectangle(Brushes.Black, e.Bounds)

        'Get the correct text to draw from the text property of the page  that you're drawing for
        Dim txtStr As String = TabControl1.TabPages(e.Index).Text
        'Draw the string, in this case, I made the text White, and the +3 merely offsets the text from the upper left corner of the tab.
        e.Graphics.DrawString(txtStr, TabControl1.Font, Brushes.White, e.Bounds.X + 3, e.Bounds.Y + 3)
    End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andrewpkCommented:
i imagine you've already checked out the   tabcontrol.backcolor  property?
0
srcalcCommented:
You should look at this link. For whatever reason, there is not a built in way to change the TabControl color. You may have to get a third-party class if possible. The only solution is the one explained in this link, which is a slightly complicated process of overriding the OnPaint method.

http://www.dotnet247.com/247reference/msgs/51/257850.aspx
0
ccuster68Commented:
Lacutah,
This was great, here is the c# code for the same thing...
 

private void tabControl_DrawItem(object sender, DrawItemEventArgs e)
{
     // This draws the background.
     e.Graphics.FillRectangle(Brushes.Black, e.Bounds);
     // Get the correct text to draw from the text property of the page  
     // that you're drawing for
     string txtStr = tabControl.TabPages[e.Index].Text;
     // Draw the string, in this case, I made the text White, 
     // and the +3 merely offsets the text from the upper left corner of the tab.
     e.Graphics.DrawString(txtStr, tabControl.Font, Brushes.White, e.Bounds.X + 3, e.Bounds.Y + 3);
}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.