procedure TMainForm.aListBoxDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
i: Integer;
position: Integer;
str: string;
begin
str := aListBox.Items.Strings[Index];
position := AnsiPos('* ', str);
if position > 0 then
begin
aListBox.Canvas.FillRect(Rect);
aListBox.Canvas.Font.Color := clRed;
aListBox.Canvas.TextOut(Rect.Left + 1, Rect.Top + 1, '* ');
end;
i := aListBox.Canvas.TextWidth('* ');
str := Copy(str, position + 2, Length(str));
aListBox.Canvas.Font.Color := clBlack;
aListBox.Canvas.TextOut(Rect.Left + 2 + i, Rect.Top + 1, str);
//aListBox.Canvas.DrawFocusRect(Rect);
end;
效果图如下: