public class CheckedImageListBox : CheckedListBox
{
protected override void OnDrawItem(DrawItemEventArgs e)
{
IDisplayGraphLinker oGraphLinker =
(IDisplayGraphLinker)this.Items[e.Index];
int nX = e.Bounds.X+2;
int nY = e.Bounds.Y+2;
//Grab the graphics object
Graphics g = e.Graphics;
Rectangle oCheckBoxRectangle = new Rectangle(nX, nY, 10, 10);
// Draw the box
g.DrawRectangle(new Pen(Color.Black, 2), oCheckBoxRectangle);
//if this item is checked, draw a tick
if(this.Items[e.Index]))//implement whether your item is checked here
{
g.DrawString(oGraphLinker.ToString(), Font, new SolidBrush(Color.Black),
e.Bounds.X+45,e.Bounds.Y+1);
g.FillRectangle(new
SolidBrush(System.Drawing.SystemColors.ActiveCapti on),
oCheckBoxRectangle.X+2, oCheckBoxRectangle.Y+2, 6, 6);
}
else
{
g.DrawString(oGraphLinker.ToString(), Font, new SolidBrush(Color.Gray),
e.Bounds.X+45,e.Bounds.Y+1);
g.FillRectangle(new SolidBrush(Color.White), oCheckBoxRectangle.X+2,
oCheckBoxRectangle.Y+2, 6, 6);
}
//now draw an icon
g.DrawImage(IMAGE, new Point(e.Bounds.X+20, e.Bounds.Y));
}
}