Пример из DRKB. Необходимо изменить свойство Style в TListBox на lbOwnerDrawFixed, иначе событие OnDrawItem никогда не произойдёт. Обработчик события OnDrawItem TListBox:
Код:
procedure TForm1.ListBox1DrawItem (Control: TWinControl; Index: Integer;Rect: TRect; State: TOwnerDrawState);
var
myColor: TColor;
myBrush: TBrush;
begin
myBrush := TBrush.Create;
with (Control as TListBox).Canvas do
begin
if not Odd(Index) then myColor := clSilver
else myColor := clYellow;
myBrush.Style := bsSolid;
myBrush.Color := myColor;
Windows.FillRect(handle, Rect, myBrush.Handle);
Brush.Style := bsClear;
TextOut(Rect.Left, Rect.Top,(Control as TListBox).Items[Index]);
MyBrush.Free;
end;
end;
или:
Код:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
With ListBox1 do begin
If odSelected in State then
Canvas.Brush.Color:=clTeal { твой цвет }
else
Canvas.Brush.Color:=clWindow;
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left+2,Rect.Top,Items[Index]);
end;
end;
С ListBox1.ItemIndex:= ListBox1.Count - 1 полностью согласен.