http://rajeshkm.blogspot.com/2006/07/how-to-change-color-of-tab-control-in.html
Be sure to read the first comment as it contains a fix that will allow you to compile the code.
Borrowed (and adjusted) code warning:
private void ChangeTabColor(object sender, DrawItemEventArgs e)
{
Font TabFont;
Brush BackBrush = new SolidBrush(Color.Green);
Brush ForeBrush = new SolidBrush(Color.Yellow);
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);
sf.Dispose();
if (e.Index == this.tabControl1.SelectedIndex)
{
TabFont.Dispose();
BackBrush.Dispose();
}
else
{
BackBrush.Dispose();
ForeBrush.Dispose();
}
}
To use this in your code, put this line in the form load event:
tabControl1.DrawItem += ChangeTabColor.
source
share