Bonjour à tous,

Je me developpe un controlutilisateur héritant d'une list box afin de me faire une listbox avec des items perso reprenant des informations d'une list<objet>.

A cette fin je me suis inspiré de : http://www.codeproject.com/Articles/15464/Extending-the-ListBox-to-show-more-complex-items

Presque tout marche comme je souhaiterais mais il y un problème. En effet, je place un "lisseret" vertical à gauche de l'item. Malheureusement je ne comprend pas pourquoi il ne s'affiche que sur la première item ou sur les autres si je descend l'ascenseur doucement. Cela parait complétement aléatoire lors de l'affichage ou non.

Voici le code que j'utilise pour dessiner l'item.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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();
 
        }
La correction a été apportée dans le code: le problèmes venait de de l'utilisation de 0,0 à la place de e.Bounds.X et e.Bounds.Y