Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Windows.Forms;
Using System.ComponentModel;
Using System.Drawing;
Using System.Drawing.Imaging;
Using System.Windows.Forms.VisualStyles;
Namespace Nereus.controls
{
public class Datagridviewprogresscolumn:datagridviewcolumn
{
Public Datagridviewprogresscolumn ()
{
Base. ValueType = typeof (float);
This. CellTemplate = new Datagridviewprogresscell ();
}
public override DataGridViewCell CellTemplate
{
Get
{
Return base. CellTemplate;
}
Set
{
Ensure the cell used for the template is a Progresscell.
if (value! = NULL &&
!value. GetType (). IsAssignableFrom (typeof (Datagridviewprogresscell)))
{
throw new InvalidCastException ("must be a Progresscell");
}
Base. CellTemplate = value;
}
}
}
public class Datagridviewprogresscell:datagridviewimagecell
{
private static Bitmap m_contentimage;
private static Bitmap emptyimage;
private static Brush ForeColor;
private bool isvisualstyled;
Static Datagridviewprogresscell ()
{
Emptyimage = new Bitmap (0x4b, 0x12, Pixelformat.format32bpppargb);
ForeColor = new SolidBrush (color.navy);
}
Public Datagridviewprogresscell ()
{
This. Value = 0f;
This. ValueType = typeof (float);
Base. Style.alignment = Datagridviewcontentalignment.middlecenter;
}
protected override Object GetFormattedValue (object value, int rowIndex, ref DataGridViewCellStyle CellStyle, TypeConverter Valuetypeconverter, TypeConverter formattedvaluetypeconverter, datagridviewdataerrorcontexts context)
{
int width = this. Owningcolumn.width;
int height = this. Owningrow.height;
this.isvisualstyled = Visualstyleinformation.isenabledbyuser & Visualstyleinformation.issupportedbyos;
M_contentimage = new Bitmap (width-4, height-4, Pixelformat.format32bpppargb);
using (Graphics m_contentgraphics = Graphics.fromimage (m_contentimage))
{
if (value = = null)
{
return emptyimage;
}
float num = (float) value;
M_contentgraphics.clear (color.transparent);
float num2 = (num > 100f)? 100f:num;
if (this.isvisualstyled)
{
Progressbarrenderer.drawhorizontalbar (M_contentgraphics, New Rectangle (2, 2, width-6, height-6));
if (num! = 0f)
{
Progressbarrenderer.drawhorizontalchunks (M_contentgraphics, New Rectangle (3, 3, ((width-8) * (int) num/100), height-8 ));
}
}
Else
{
M_contentgraphics.drawrectangle (Pens.black, 2, 2, width-6, height-6);
if (num! = 0f)
{
M_contentgraphics.fillrectangle (Brushes.blue, 3, 3, ((width-8) * (int) num/100), height-8);
}
}
RectangleF rect = new RectangleF (0, 0, width, height);
StringFormat SF = new StringFormat ();
sf. Alignment = Stringalignment.center;
sf. LineAlignment = Stringalignment.center;
Contentgraphics.drawstring (Num. ToString ("0.00") + "%", base. Datagridview.font, ForeColor, rect, SF);//display format: 0%
M_contentgraphics.drawstring (Num. ToString () + "%", base. Datagridview.font, ForeColor, rect, SF);
return m_contentimage;
}
}
}
}