一、改变标签颜色
ItemTabControl.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;ItemTabControl.DrawItem += new System.Windows.Forms.DrawItemEventHandler(ItemTabControl_DrawItem);
private void ItemTabControl_DrawItem(object sender, DrawItemEventArgs e){//标签默认文字颜色SolidBrush DefaultFrontBrush = new SolidBrush(Color.Black);//改变的标签背景颜色SolidBrush BackBrush = new SolidBrush(Color.FromArgb(255, 0, 0));//标签默认背景颜色SolidBrush BackBrushDefault = new SolidBrush(Color.Transparent);//标签文字,选中的标签文字加粗Font font = new Font("宋体", 9);Font fontbold = new Font("宋体", 9, FontStyle.Bold);//设置文字对齐方式StringFormat StringF = new StringFormat();StringF.Alignment = StringAlignment.Center;StringF.LineAlignment = StringAlignment.Center;for (int i = 0; i < MainTabRes.Count; i++){//获取标签头工作区域Rectangle Rec = ItemTabControl.GetTabRect(i);string text = ItemTabControl.TabPages[i].Text;if (MainTabRes[i] == false)//MainTabRes指示要改变背景色的标签索引,List<bool> MainTabRes = new List<bool>();{e.Graphics.FillRectangle(BackBrush, Rec);}else{e.Graphics.FillRectangle(BackBrushDefault, Rec);} if (i == ItemTabControl.SelectedIndex){//绘制标签头文字 e.Graphics.DrawString(text, fontbold, DefaultFrontBrush, Rec, StringF);}else{e.Graphics.DrawString(text, font, DefaultFrontBrush, Rec, StringF);}}}