笨辦法,看信息內容而定:Style = lbOwnerDrawFixed,先設置一個默認字體顏色(黑色),加以下2種(暗紅、綠色)就有3種了。
procedure TfrmMain.MsgListDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
position: Integer;
str: string;
begin
str := MsgList.Items.Strings[Index];
position := AnsiPos('!', str);
if position > 0 then
begin
MsgList.Canvas.FillRect(Rect);
MsgList.Canvas.Font.Color := clMaroon;
end;
position := AnsiPos('未', str);
if position > 0 then
begin
MsgList.Canvas.FillRect(Rect);
MsgList.Canvas.Font.Color := clGreen;
end;
MsgList.Canvas.TextOut(Rect.Left + 1, Rect.Top + 1, MsgList.Items.Strings[Index]);
end;