如何重画tabcontrol 的背景色
kv888 2008-07-07 10:20:09 private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Font f;
Brush backBrush;
Brush foreBrush;
if (e.Index == this.tabControl1.SelectedIndex)
{
//f = new Font(e.Font, FontStyle.Italic | FontStyle.Bold);
f = new Font(e.Font, FontStyle.Regular);
//backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.Blue, Color.Red, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.FromArgb(223, 232, 247), Color.FromArgb(223, 232, 247), System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
foreBrush = Brushes.Black;
}
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();
}
}
以上代码只能改变已经创建的tabpage的颜色 可以剩下右侧的区域还是灰色的 我想把整个tabcontrol都改变成其它颜色