C# tabcontrol当标签页被选中后改变颜色
private TabControl tabsControl = new TabControl();
tabsControl.DrawMode = TabDrawMode.OwnerDrawFixed;
tabsControl.DrawItem += new DrawItemEventHandler(this.tabsControl_DrawItem);
private void tabCameraSubjectTuingLogsControl_DrawItem(object sender, DrawItemEventArgs e)
{
#region 重绘标签头=======================
SolidBrush back;
SolidBrush white;
if (e.Index == tabsControl.SelectedIndex)
{
back = new SolidBrush(Color.Wheat);
white = new SolidBrush(Color.Blue);
}
else
{
back = new SolidBrush(Color.SeaShell);
white = new SolidBrush(Color.Blue);
}
StringFormat sf = new StringFormat()
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center,
};
Rectangle rec = tabsControl.GetTabRect(e.Index);
e.Graphics.FillRectangle(back, rec);
e.Graphics.DrawString(tabsControl.TabPages[e.Index].Text, new Font("微软雅黑", 8, FontStyle.Bold), white, rec, sf);
#endregion
}