Commit 44e479b4 authored by tr's avatar tr

1、定制Tab控件优化:肩线只绘制一次

parent 957c0103
......@@ -76,9 +76,19 @@ namespace Tools.MyControls
/// <param name="e"></param>
protected override void OnPaintBackground(PaintEventArgs e)
{
var g = e.Graphics;
//绘制控件背景
var brush = new SolidBrush(this.BackgroundColor);
e.Graphics.FillRectangle(brush, e.ClipRectangle);
g.FillRectangle(brush, e.ClipRectangle);
//扩展:绘制肩线(仅绘制一次:用以突出选中效果)
Rectangle client = this.ClientRectangle;
var x = client.X;
var y = client.Y + this.ItemSize.Height + 2;
var location = new Point(x + 2, y); //左右各留2像素
var size = new Size(client.Width - 3, 2);
var shoulder = new Rectangle(location, size);
var shoulderBrush = new SolidBrush(this.TabActivedBackColor); //肩线为激活颜色
g.FillRectangle(shoulderBrush, shoulder);
}
/// <summary>
/// 重写:绘制方法
......@@ -98,7 +108,6 @@ namespace Tools.MyControls
var BackColor = IsSelected ? TabActivedBackColor : isHover ? TabDeactivedBackColorHover : TabDeactivedBackColor;
var FontColor = IsSelected ? TabActivedFontColor : isHover ? TabDeactivedFontColorHover : TabDeactivedFontColor;
//画笔、画刷准备
var backPen = new Pen(BackColor);
var backBrush = new SolidBrush(BackColor);
var fontBrush = new SolidBrush(FontColor);
//绘制并填充矩形框:背景
......@@ -106,21 +115,8 @@ namespace Tools.MyControls
//绘制标题
var title = this.TabPages[index].Text;
g.DrawString(title, this.Font, fontBrush, tabRect, this.fmt);
//扩展:绘制肩线(每轮绘制一次)
if (index == 0)
{
Rectangle client = this.ClientRectangle;
var x = client.X;
var y = client.Y + tabRect.Height + 2;
var location = new Point(x + 2, y); //左右各留2像素
var size = new Size(client.Width - 3, 2);
var shoulder = new Rectangle(location, size);
var shoulderBrush = new SolidBrush(this.TabActivedBackColor); //肩线为激活颜色
g.FillRectangle(shoulderBrush, shoulder);
}
}
//扩展:绘制标签项边框线
//扩展:绘制标签项边框线(每轮绘制一次:用以突出选中效果)
this.DrawTabsBorder(g);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment