|
Besoin d'un développeur C#/VB/.NET ? Contactez nous
Réactivité, coûts modérés.
Maxence DELANNOY - Tél. : 09.70.46.32.55
|
|
Soumis par Maxence le jeu, 04/03/2010 - 20:56
Il faut passer la propriété DrawMode de la ListBox à OwnerDrawFixed et ajouter le code suivant dans l'événement OnDraw :
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();
ListBox lb = sender as ListBox;
// Calcule les dimensions du texte
SizeF stringSize = new SizeF();
stringSize = e.Graphics.MeasureString(lb.Items[e.Index].ToString(), e.Font);
e.Graphics.DrawString(
lb.Items[e.Index].ToString(),
e.Font,
new SolidBrush(e.ForeColor),
new PointF(e.Bounds.Right - stringSize.Width, e.Bounds.Y)
);
}Si ça peut faire gagner 5 minutes à quelqu'un...


Poster un nouveau commentaire