Вроде придумал, вот:
| Код | procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); const FLAG = #1; var Line, Bold: AnsiString; i: Integer; begin with (Control as TListBox), Canvas do // Style = lbOwnerDrawFixed begin Line := Items[Index]; Bold := Edit1.Text; Bold := StringReplace(Line, Bold, StringOfChar(FLAG, Length(Bold)), [rfReplaceAll, rfIgnoreCase]); FillRect(Rect); Brush.Style := bsClear; Inc(Rect.Left, 2); for i := 1 to Length(Line) do begin if Bold[i] = FLAG then Font.Style := [fsBold, fsUnderline]; TextOut(Rect.Left, Rect.Top, Line[i]); Inc(Rect.Left, TextWidth(Line[i])); Font.Style := []; end; end; end;
|
В примере выделяются все вхождения подстроки. |