const
Hintergrund: TColor = clwhite;
balken: TColor = clblack;
Fontcolor: TColor = clnavy;
selectedFontColor: TColor = claqua;
sonderFarbe: TColor = clred;
sonderSelect: TColor = clyellow;
Suchbegriff: string = 'es';
procedure TForm1.FormCreate(Sender: TObject);
begin
listbox1.style := lbOwnerDrawFixed;
listbox1.color := Hintergrund;
// --------- nur zum Testen ------------
Listbox1.items.add('Normal1');
Listbox1.items.add('Normal2');
Listbox1.items.add('Test1');
Listbox1.items.add('Normal3');
Listbox1.items.add('Test2');
Listbox1.items.add('Normal4');
Listbox1.items.add('Normal5');
// -------------------------------------
end;
function testen(s: string): boolean;
begin
result := pos(suchbegriff, s) > 0;
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with listbox1.canvas do begin
if odSelected in State then begin
brush.color := balken;
if testen(listbox1.items[index]) then
font.color := sonderSelect else
font.color := selectedFontColor;
end else begin
brush.color := Hintergrund;
if testen(listbox1.items[index]) then
font.color := sonderFarbe else
font.color := FontColor;
end;
fillrect(rect);
drawtext(handle, pchar(listbox1.items[index]),
length(listbox1.items[index]), rect,
DT_VCENTER or DT_SINGLELINE);
end;
end;