using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Rs.Controls { public class TabControlEx : TabControl { public TabControlEx() { SizeMode = TabSizeMode.Fixed; ItemSize = new System.Drawing.Size(50, 30); this.DrawItem += (s, e) => { SolidBrush _Brush = new SolidBrush(Color.White);//单色画刷 RectangleF _TabTextArea = (RectangleF)this.GetTabRect(e.Index);//绘制区域 StringFormat _sf = new StringFormat();//封装文本布局格式信息 _sf.LineAlignment = StringAlignment.Center; _sf.Alignment = StringAlignment.Center; Rectangle rec01 = this.ClientRectangle; //设置工作区背景色 e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(11, 16, 36)), rec01); //e.Graphics.FillRectangle(new SolidBrush(Color.Blue), _TabTextArea); //e.Graphics.DrawString(this.Controls[e.Index].Text, this.Font, _Brush, _TabTextArea, _sf); for (int i = 0; i < this.TabPages.Count; i++) { if (this.SelectedIndex == i) { //绑定选项卡 Rectangle rec = this.GetTabRect(i); //设置选项卡背景 //e.Graphics.FillRectangle(back, rec); //e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(57, 136, 203)), rec); e.Graphics.FillRectangle(new SolidBrush(Color.Green), rec); e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.White)), rec); //设置选项卡字体及颜色 e.Graphics.DrawString(this.TabPages[i].Text, new Font("微软雅黑", 9), _Brush, rec, _sf); } else { //绑定选项卡 Rectangle rec = this.GetTabRect(i); //设置选项卡背景 //e.Graphics.FillRectangle(back, rec); e.Graphics.FillRectangle(new SolidBrush(Color.Black), rec); e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.White)), rec); //设置选项卡字体及颜色 e.Graphics.DrawString(this.TabPages[i].Text, new Font("微软雅黑", 9), _Brush, rec, _sf); } } }; } } }