注意,是想改变行的颜色,而不是字体颜色,网上的帖子都是如何改变字体颜色的,,
我在DrawItem事件中写了如下代码,但结果是什么都不显示; if (lstAlert.ItemIndex mod 2) =0 then
lstAlert.Canvas.Brush.Color := clSkyBlue
else
lstAlert.Canvas.Brush.Color := clWhite;
我在DrawItem事件中写了如下代码,但结果是什么都不显示; if (lstAlert.ItemIndex mod 2) =0 then
lstAlert.Canvas.Brush.Color := clSkyBlue
else
lstAlert.Canvas.Brush.Color := clWhite;
lstAlert.Canvas.Brush.Color := clSkyBlue
else
lstAlert.Canvas.Brush.Color := clWhite; SetBkMode(lstAlert.Canvas.Handle, TRANSPARENT);
lstAlert.Canvas.Rectangle(Rect);
lstAlert.Canvas.TextOut(Rect.left, Rect.Top, ListBox1.Items.Strings[Index]);
begin
if Index mod 2 <>0 then
Brush.Color := clred
else
Brush.Color := clLime;
FillRect(Rect);
TextOut(Rect.Left+2, rect.Top, (Control as TListBox).Items[Index]);
end;
然后在drawitem事件中写:
if (Index mod 2) =0 then
lstAlert.Canvas.Brush.Color := clSkyBlue
else
lstAlert.Canvas.Brush.Color := clWhite;
lstAlert.Canvas.FillRect(Rect);
lstAlert.Canvas.TextOut(Rect.Left+2, rect.Top, (Control as TListBox).Items[Index]);