Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Set backcolor on TabControl

Posted on 2008-10-10
4
1,196 Views
Last Modified: 2012-05-05
I need to remove or set the backcolor on a TabControl, but there is no "BackColor" option on this control - what to do?

Thanks
TabColor.jpg
0
Comment
Question by:Loeffe
  • 2
4 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 125 total points
ID: 22686344
0
 
LVL 15

Assisted Solution

by:angus_young_acdc
angus_young_acdc earned 125 total points
ID: 22686373
1. Set the TabControl's DrawMode to OwnerDraw
2. Handle the DrawItem event to draw things yourself
You may call the following method at the DrawItem event of tab control to test this.



private void ChangeTabColor(DrawItemEventArgs e)
{
Font TabFont;
Brush BackBrush = new SolidBrush(Color.Green); //Set background color
Brush ForeBrush = new SolidBrush(Color.Yellow);//Set foreground color
if (e.Index == this.tabControl1.SelectedIndex)
{
TabFont = new Font(e.Font, FontStyle.Italic FontStyle.Bold);
}
else
{
TabFont = e.Font;
}
string TabName = this.tabControl1.TabPages[e.Index].Text;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
e.Graphics.FillRectangle(BackBrush, e.Bounds);
Rectangle r = e.Bounds;
r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3);
e.Graphics.DrawString(TabName, TabFont, ForeBrush, r, sf);
//Dispose objects
sf.Dispose();
if (e.Index == this.tabControl1.SelectedIndex)
{
TabFont.Dispose();
BackBrush.Dispose();
}
else
{
BackBrush.Dispose();
ForeBrush.Dispose();
}
}

http://rajeshkm.blogspot.com/2006/07/how-to-change-color-of-tab-control-in.html
0
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 22686378
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question