
27.11.2010, 20:57
|
Активный
|
|
Регистрация: 25.02.2008
Сообщения: 395
Репутация: -599
|
|
Решение найдено.
Можно использовать обычный ListBox и воспользоваться отрисовкой компонента.
Код:
procedure TListTest.ListBox1DrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
const
HighLight = 'LINE';
var
TempLine, TempText, TempHigh: string;
TempLeft, TempTop, TempStart: Integer;
OldColor: TColor;
begin
with (Control as TListBox).Canvas do
begin
FillRect(Rect);
TempLeft := Rect.Left + 3;
TempTop := Rect.Top + 1;
TempLine := (Control as TListBox).Items[Index];
while TempLine > '' do
begin
TempStart := Pos(HighLight, AnsiUpperCase(TempLine));
if TempStart > 0 then
begin
TempText := Copy(TempLine, 1, TempStart - 1);
TempHigh := Copy(TempLine, TempStart, Length(HighLight));
Delete(TempLine, 1, TempStart + Length(HighLight) - 1);
end
else
begin
TempText := TempLine;
TempHigh := '';
TempLine := '';
end;
if TempText > '' then
begin
TextOut(TempLeft, TempTop, TempText);
Inc(TempLeft, TextWidth(TempText));
end;
if TempHigh > '' then
begin
OldColor := Font.Color;
if odSelected in State then
Font.Color := clYellow
else
Font.Color := clBlue;
TextOut(TempLeft, TempTop, TempHigh);
Inc(TempLeft, TextWidth(TempHigh));
Font.Color := OldColor;
end;
end;
end;
end;
Упростил вариант до:
Код:
with (Control as TListBox).Canvas do
begin
if index mod 2 <>0 then
begin
Font.Color:=clBlack;
brush.Color:=clSkyBlue;
end
else
begin
Font.Color:=clBlack;
brush.Color:=clWhite;
end;
FillRect(Rect);
TextOut(Rect.Left, Rect.Top, (Control as TListBox).Items[Index]);
end;
|