怎么修改tabcontrol当前选中的选项卡的标题字体颜色啊,紧急求助!!
1个回答
2013-05-19
展开全部
先绑定事件
tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
tabControl1.DrawItem += new DrawItemEventHandler(this.TabControl_DrawItem);
具体事件
///
/// 设置选中选项卡与未选中选项卡背景色
///
///
///
private void TabControl_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Font fntTab;
Brush bshBack;
Brush bshFore;
if (e.Index == this.tabControl1.SelectedIndex)
{
fntTab = new Font(e.Font, FontStyle.Bold);
bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.Control, SystemColors.Control, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
bshBack = new SolidBrush(Color.FromArgb(((int)(((byte)(23)))), ((int)(((byte)(151)))), ((int)(((byte)(248))))));
bshFore = Brushes.White;
}
else
{
fntTab = e.Font;
bshBack = new SolidBrush(Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(208)))), ((int)(((byte)(200))))));
bshFore = new SolidBrush(Color.Black);
}
string tabName = tabControl1.TabPages[e.Index].Text;
StringFormat sftTab = new StringFormat();
e.Graphics.FillRectangle(bshBack, e.Bounds);
Rectangle recTab = e.Bounds;
recTab = new Rectangle(recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);
}
tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
tabControl1.DrawItem += new DrawItemEventHandler(this.TabControl_DrawItem);
具体事件
///
/// 设置选中选项卡与未选中选项卡背景色
///
///
///
private void TabControl_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Font fntTab;
Brush bshBack;
Brush bshFore;
if (e.Index == this.tabControl1.SelectedIndex)
{
fntTab = new Font(e.Font, FontStyle.Bold);
bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.Control, SystemColors.Control, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
bshBack = new SolidBrush(Color.FromArgb(((int)(((byte)(23)))), ((int)(((byte)(151)))), ((int)(((byte)(248))))));
bshFore = Brushes.White;
}
else
{
fntTab = e.Font;
bshBack = new SolidBrush(Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(208)))), ((int)(((byte)(200))))));
bshFore = new SolidBrush(Color.Black);
}
string tabName = tabControl1.TabPages[e.Index].Text;
StringFormat sftTab = new StringFormat();
e.Graphics.FillRectangle(bshBack, e.Bounds);
Rectangle recTab = e.Bounds;
recTab = new Rectangle(recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询