SoFunction
Updated on 2025-03-06

C# How to change tabControl tab color

This article shows how to change the color of tabControl tab in C#. Share it for your reference, as follows:

private void Form1_Load(object sender, EventArgs e)
{
  this. = ;
  this. += new DrawItemEventHandler(this.tabControl1_DrawItem);
}
private void tabControl1_DrawItem(object sender,  e)
{
  StringFormat sf = new StringFormat();
   = ;
   = ;
  if ( == )
    (, , , , );
  else
    (, , , , );
  (((TabControl)sender).TabPages[].Text,
  , new SolidBrush(), , sf);
}

1. Add the following statement to the constructor of the Form class:

this. = ;
this. += new DrawItemEventHandler(this.tabControl1_DrawItem);

2. Implement the following functions:

private void tabControl1_DrawItem(object sender,  e)
{
   Font fntTab;
   Brush bshBack;
   Brush bshFore;
   if (  == this.)
   {
     fntTab = new Font(, );
     bshBack = new .(, , , .);
     bshFore = ;
   }
   else
   {
     fntTab = ;
     bshBack = new SolidBrush( );
     bshFore = new SolidBrush();
   }
   string tabName  = this.[].Text;
   StringFormat sftTab = new StringFormat();
   (bshBack, );
   Rectangle  recTab = ;
   recTab = new Rectangle( ,   + 4,  ,   - 4);
   (tabName, fntTab, bshFore, recTab, sftTab);
}

For more information about C# related content, please check out the topic of this site:C# data structure and algorithm tutorial》、《Tutorial on the usage of common C# controls》、《Introduction to C# object-oriented programming tutorial"and"Summary of thread usage techniques for C# programming

I hope this article will be helpful to everyone's C# programming.