代码如下,重绘CheckBox,CheckBox是在datagridview里面的一列但是没有用
public class LDDataGridViewCheckBoxColumn : DataGridViewCheckBoxColumn
{
private Color _CheckColor = Color.Blue;
Color CheckBackColor = Color.Gainsboro;
bool isDraw = false;
[Category(“设置”), Description(“选项框的颜色”)]
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
SizeF DSize = g.MeasureString(“√”, new Font(new FontFamily(“宋体”), 18));
this.Height = (int)DSize.Height;
Rectangle Outrect = new Rectangle(0, this.Height / 2 – 6, 12, 12);
Rectangle Inrect = new Rectangle(1, this.Height / 2 – 6 + 1, 10, 10);
GraphicsPath path = new GraphicsPath();
path.AddRectangle(Outrect);
g.DrawPath(new Pen(this.Enabled ? CheckColor : Color.Silver), path);
g.FillPath(new SolidBrush(CheckBackColor), path);
if (Checked)
{
g.DrawString(“√”, new Font(new FontFamily(“宋体”), 18), new SolidBrush(this.Enabled ? CheckColor : Color.Silver), new PointF(6 – DSize.Width / 2, this.Height / 2 – Height / 2 – 1));
}
}
}
public class LDDataGridViewCheckBoxColumn : DataGridViewCheckBoxColumn
{
private Color _CheckColor = Color.Blue;
Color CheckBackColor = Color.Gainsboro;
bool isDraw = false;
[Category(“设置”), Description(“选项框的颜色”)]
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
SizeF DSize = g.MeasureString(“√”, new Font(new FontFamily(“宋体”), 18));
this.Height = (int)DSize.Height;
Rectangle Outrect = new Rectangle(0, this.Height / 2 – 6, 12, 12);
Rectangle Inrect = new Rectangle(1, this.Height / 2 – 6 + 1, 10, 10);
GraphicsPath path = new GraphicsPath();
path.AddRectangle(Outrect);
g.DrawPath(new Pen(this.Enabled ? CheckColor : Color.Silver), path);
g.FillPath(new SolidBrush(CheckBackColor), path);
if (Checked)
{
g.DrawString(“√”, new Font(new FontFamily(“宋体”), 18), new SolidBrush(this.Enabled ? CheckColor : Color.Silver), new PointF(6 – DSize.Width / 2, this.Height / 2 – Height / 2 – 1));
}
}
}
解决方案
40
参考
https://msdn.microsoft.com/zh-cn/library/7fb61s43(v=vs.110).aspx
https://msdn.microsoft.com/zh-cn/library/7fb61s43(v=vs.110).aspx