[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1069
  • Last Modified:

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.
0
eekj
Asked:
eekj
2 Solutions
 
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
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now