vla j'aimerai mettre une couleur dans une ligne specifique de la list box
j'ia pas tres bien compris l'evenement drawitem, il s'execute lorsque je fais un add??
comment changer la couleur d'une ligne ?
merci?
Version imprimable
vla j'aimerai mettre une couleur dans une ligne specifique de la list box
j'ia pas tres bien compris l'evenement drawitem, il s'execute lorsque je fais un add??
comment changer la couleur d'une ligne ?
merci?
Avant de poster sur le forum, t'as été regardé dans l'aide (TCustomListBox::OnDrawItem) ? c'est super bien expliqué et y'a un exemple en +
exemple: sur ta fiche tu met un ListBox avec quelques Items.
tu dessine tout dans l'evenement OnDrawItem:
Mettre la propriété Style de ta ListBox à : lbOwnerDrawFixed.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State) { if (Index == 2) //ligne dont tu veut changer la couleur { ((TListBox *)Control)->Canvas->Brush->Color = clRed; ((TListBox *)Control)->Canvas->FillRect(Rect); } // Il faut reécrire tout tes Items ((TListBox *)Control)->Canvas-> TextOut(Rect.Left+2,Rect.Top+2, ((TListBox *)Control)->Items->Strings[Index]); }
Autre exemple (affichage correct du rectangle de focalisation)
Ne pas oublier la propriété Style de ta ListBox à : lbOwnerDrawFixed.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State) { TCanvas *pCanvas = ((TListBox *)Control)->Canvas; if ((Index%2)==0) pCanvas->Brush->Color = clYellow; // met 1 ligne sur 2 jaune if(State.Contains(odSelected)) //ligne selectionnée { pCanvas->Brush->Color = clRed; pCanvas->FillRect(Rect); pCanvas->Font->Color = clYellow; } else pCanvas->FillRect(Rect); //Les autres lignes //Il faut réécrire les Items. pCanvas->TextOut(Rect.Left+5,Rect.Top+2, ((TListBox *)Control)->Items->Strings[Index]); }
je te remercie grandement CGI, Merci
Merci CGI,
Avec ton call j'ai pu supprimer des lignes qui apparaissaient quand je survolait mon combo.