Код:
TForm1 = class(TForm)
private
ChangeColor : Boolean;
public
end;
....
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with (Control as TListBox).Canvas do begin
if not (odSelected in State) then
if ChangeColor and (Index in [3..5]) then
Brush.Color := clSkyBlue
else
Brush.Color := clWhite;
FillRect(Rect);
TextOut(Rect.Left + 2, Rect.Top, (Control as TListBox).Items[Index])
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ChangeColor := not ChangeColor; //каждое нажатие на кнопку включае/выключает подсветку
ListBox1.Invalidate;
end;
А без ListBox1DrawItem все равно не обойтись.