1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
public void drawItem(DrawItemEventArgs e, Padding margin,
Font titleFont, Font detailsFont, StringFormat aligment,
Size imageSize)
{
// if selected, mark the background differently
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
e.Graphics.FillRectangle(Brushes.CornflowerBlue, e.Bounds);
}
else
{
e.Graphics.FillRectangle(Brushes.Beige, e.Bounds);
}
// draw some item separator
e.Graphics.DrawLine(Pens.DarkGray, e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
// draw item image
e.Graphics.DrawImage(this.ItemImage, e.Bounds.X + margin.Left, e.Bounds.Y + margin.Top, imageSize.Width, imageSize.Height);
// calculate bounds for title text drawing
Rectangle titleBounds = new Rectangle(e.Bounds.X + margin.Horizontal + imageSize.Width,
e.Bounds.Y + margin.Top,
e.Bounds.Width - margin.Right - imageSize.Width - margin.Horizontal,
(int)titleFont.GetHeight() + 2);
// calculate bounds for details text drawing
Rectangle detailBounds = new Rectangle(e.Bounds.X + margin.Horizontal + imageSize.Width,
e.Bounds.Y + (int)titleFont.GetHeight() + 2 + margin.Vertical + margin.Top,
e.Bounds.Width - margin.Right - imageSize.Width - margin.Horizontal,
e.Bounds.Height - margin.Bottom - (int)titleFont.GetHeight() - 2 - margin.Vertical - margin.Top);
// draw the text within the bounds
e.Graphics.DrawString(this.Title, titleFont, Brushes.Black, titleBounds, aligment);
e.Graphics.DrawString(this.Details, detailsFont, Brushes.DarkGray, detailBounds, aligment);
//---------- LA PARTIE QUI POSE PROBLEME ----------//
Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Y, 5, e.Bounds.Height);
e.Graphics.DrawRectangle(new Pen(Color.Black), rect);
e.Graphics.FillRectangle(new SolidBrush(Color.Red), rect);
// put some focus rectangle
e.DrawFocusRectangle();
} |
Partager