Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  




           


Color the Background of a TabControl
To set the color of a tabControl to something other than 'Control', set the DrawMode property on the tabControl.
DrawMode = OwnerDrawFixed.

Then, handle the DrawItem event; you will need to draw the tab text yourself, as well as optionally setting the background color.

private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
string tabName = this.tabControl1.TabPages[e.Index].Text;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
Rectangle centerRect = new Rectangle(e.Bounds.X+3,e.Bounds.Y+3,e.Bounds.Width-6,e.Bounds.Height-3);
e.Graphics.FillRectangle(Brushes.WhiteSmoke, centerRect); // colors the tab caption
e.Graphics.DrawString("Filter", new Font("Arial", 9, FontStyle.Regular),System.Drawing.Brushes.Black, centerRect, sf);
} // load

Since this only colors the actual tab captions, you need to color each tab page the same color as here. Do this by setting the BackColor of each tab page to the color you used here.

Note that we only colored an area excluding a 3px border. This is because the tabPages have, by default, a 3px border around them, so our tab captions need to match that.

Created By: amos 3/20/2006 12:13:00 AM
Updated: 7/14/2009 12:38:13 PM