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
| procedure TMainForm.ListBoxMainDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
pCanvas : TCanvas;
begin
pCanvas := (Control as TListBox).Canvas;
if (((Control as TListBox).Items.Strings[Index] = 'Texte1') or
((Control as TListBox).Items.Strings[Index] = 'Texte2') or
((Control as TListBox).Items.Strings[Index] = 'Texte3')) then
pCanvas.Brush.Color := $F5D68D;
if ((Control as TListBox).Items.Strings[Index] = 'Texte4') then
pCanvas.Brush.Color := $7E9CFF;
// Lorsque la ligne est sélectionnée
if (odSelected in State) then
begin
pCanvas.Brush.Color := $C56A31;
pCanvas.FillRect(Rect);
pCanvas.Font.Color := clWhite;
end else
pCanvas.FillRect(Rect); //Les autres lignes
// Ecrire les Items.
pCanvas.TextOut(Rect.Left+5,Rect.Top,
(Control as TListBox).Items.Strings[Index]); // +5, +2
end; |