设置TabPage标头颜色

设置TabPage标头颜色,第1张

设置TabPage标头颜色

如果要给选项卡上色,请尝试以下代码:

this.tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;this.tabControl1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.tabControl1_DrawItem);private Dictionary<TabPage, Color> TabColors = new Dictionary<TabPage, Color>();private void SetTabHeader(TabPage page, Color color){    TabColors[page] = color;    tabControl1.Invalidate();}private void tabControl1_DrawItem(object sender, DrawItemEventArgs e){    //e.DrawBackground();    using (Brush br = new SolidBrush (TabColors[tabControl1.TabPages[e.Index]]))    {        e.Graphics.FillRectangle(br, e.Bounds);        SizeF sz = e.Graphics.MeasureString(tabControl1.TabPages[e.Index].Text, e.Font);        e.Graphics.DrawString(tabControl1.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + (e.Bounds.Width - sz.Width) / 2, e.Bounds.Top + (e.Bounds.Height - sz.Height) / 2 + 1);        Rectangle rect = e.Bounds;        rect.Offset(0, 1);        rect.Inflate(0, -1);        e.Graphics.DrawRectangle(Pens.DarkGray, rect);        e.DrawFocusRectangle();    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5005494.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存