class DataGridViewProgressColumn : DataGridViewImageColumn
{
public DataGridViewProgressColumn()
{
this.CellTemplate = new DataGridViewProgressCell();
}
}
class DataGridViewProgressCell : DataGridViewImageCell
{
public object progressCellLock = new object();
public Image emptyImage;
public DataGridViewProgressCell()
{
this.ValueType = typeof(double);
emptyImage = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
}
protected override object GetFormattedValue(object value,
int rowIndex, ref DataGridViewCellStyle cellStyle,
TypeConverter valueTypeConverter,
TypeConverter formattedValueTypeConverter,
DataGridViewDataErrorContexts context)
{
return emptyImage;
}
public new double Value
{
set
{
lock (progressCellLock)
{
try
{
base.Value = Math.Round(value, 2);
}
catch { }
}
}
get
{
return double.Parse(base.Value.ToString());
}
}
private int Height = 23;
private int Width = 210;
private Color progressColor = System.Drawing.Color.FromArgb(((int)(((byte)(67)))), ((int)(((byte)(222)))), ((int)(((byte)(166)))));
protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
base.Paint(g, clipBounds, cellBounds,
rowIndex, cellState, value, formattedValue, errorText,
cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));
Graphics graphics = g;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
using (Pen pen5 = new Pen(Color.White, Height - 2))
{
pen5.StartCap = LineCap.Round;
pen5.EndCap = LineCap.Round;
graphics.DrawLine(pen5, cellBounds.X + 30, cellBounds.Y + 30, cellBounds.X + Width + 30, cellBounds.Y + 30);
}
using (Pen pen6 = new Pen(progressColor, Height - 2))
{
pen6.StartCap = LineCap.Round;
pen6.EndCap = LineCap.Round;
int num4 = 0;
if (Value > 0) num4 = (int)Math.Ceiling(Width * Value);
graphics.DrawLine(pen6, cellBounds.X + 30, cellBounds.Y + 30, cellBounds.X + num4 + 30, cellBounds.Y + 30);
}
}
}
DataGridView进度条 DataGridViewProgressColumn
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- https://github.com/fems1888/SelfTestLib
- 先上效果图: Demo地址: https://github.com/liys666666/LiysProgress...
- 这篇介绍的是CAShaperLayer制作一个直线进度条,圆环进度条,注水动画;话不多说,直接代码 GitHub工...
- 大家好,今天给大家介绍一部科幻电影《人工智能 灭绝危机》 生化危机之后,地球被毁坏,人们只能躲在地下避难。地球的环...