注意,是想改变行的颜色,而不是字体颜色,网上的帖子都是如何改变字体颜色的,,
我在DrawItem事件中写了如下代码,但结果是什么都不显示;  if (lstAlert.ItemIndex mod 2) =0 then
    lstAlert.Canvas.Brush.Color := clSkyBlue
  else
    lstAlert.Canvas.Brush.Color := clWhite;

解决方案 »

  1.   

    这里,所有的东西都需要自己画了。  if (Index mod 2) =0 then
        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]);
      

  2.   

    http://dev.csdn.net/article/54/54645.shtm
      

  3.   

        with (Control as TListBox).Canvas do
        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;
      

  4.   

    你要把lisbox的style属性改成lbOwnerDrawVariable.
    然后在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]);