们,问下本人的OnPaint事件为什么没有用,重绘没出来

.Net技术 码拜 8年前 (2016-03-10) 1107次浏览
代码如下,重绘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));
}
}
解决方案

40

参考
https://msdn.microsoft.com/zh-cn/library/7fb61s43(v=vs.110).aspx

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明们,问下本人的OnPaint事件为什么没有用,重绘没出来
喜欢 (0)
[1034331897@qq.com]
分享 (0)