tabControl 的tab标签改色 加字

this.tabControl1.TabPages[0].Text = "XX"; this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed; 

 

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e) { Font f; Brush backBrush; Brush foreBrush; if (e.Index == this.tabControl1.SelectedIndex) { f = new Font(e.Font, FontStyle.Italic | FontStyle.Bold); backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.DodgerBlue, Color.White, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal); foreBrush = Brushes.PowderBlue; } else { f = e.Font; backBrush = new SolidBrush(e.BackColor); foreBrush = new SolidBrush(e.ForeColor); } string tabName = this.tabControl1.TabPages[e.Index].Text; StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; e.Graphics.FillRectangle(backBrush, e.Bounds); Rectangle r = e.Bounds; r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3); e.Graphics.DrawString(tabName, f, foreBrush, r, sf); sf.Dispose(); if (e.Index == this.tabControl1.SelectedIndex) { f.Dispose(); backBrush.Dispose(); } else { backBrush.Dispose(); foreBrush.Dispose(); } } 

你可能感兴趣的:(C#)