When you select a tab, it has a white color (as in the screenshot).
How to change to another color?
If this is your TabControl
, then you need to set it to DrawMode = TabDrawMode.OwnerDrawFixed
, and draw in the DrawItem
event as you want, for example:
public partial class Form1 : Form { public Form1() { InitializeComponent(); tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed; } private void tabControl1_DrawItem(object sender, DrawItemEventArgs e) { e.Graphics.SetClip(e.Bounds); string text = tabControl1.TabPages[e.Index].Text; SizeF sz = e.Graphics.MeasureString(text, e.Font); bool bSelected = (e.State & DrawItemState.Selected) == DrawItemState.Selected; using (SolidBrush b = new SolidBrush(bSelected ? SystemColors.Highlight : SystemColors.Control)) e.Graphics.FillRectangle(b, e.Bounds); using (SolidBrush b = new SolidBrush(bSelected ? SystemColors.HighlightText : SystemColors.ControlText)) e.Graphics.DrawString(text, e.Font, b, e.Bounds.X + 2, e.Bounds.Y + (e.Bounds.Height - sz.Height) / 2); if (tabControl1.SelectedIndex == e.Index) e.DrawFocusRectangle(); e.Graphics.ResetClip(); } }
It should turn out like this:
In TabControl, open the tabPages property and set background color for each tab.
Source: https://ru.stackoverflow.com/questions/505353/
All Articles