在ViewStyle=vsReport的情况下,希望显示不同颜色的字体。在ListView1CustomDrawSubItem事件中可以控制,但怎么样得到Item.SubItems显示的位置呢?

解决方案 »

  1.   

    方法如下,不需要得到Item.SubItems显示的位置,因为ListView会自动画,你只需要设置好画布就行了:
    procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
      Item: TListItem; SubItem: Integer; State: TCustomDrawState;
      var DefaultDraw: Boolean);
    begin
      case SubItem of
        1:
          begin
            ListView1.Canvas.Font.Color := clBlue;
            ListView1.Canvas.Font.Name :='宋体';
          end;
        2:
          begin
            ListView1.Canvas.Font.Color := clRed;
            ListView1.Canvas.Font.Name :='黑体';
          end;
      else
        begin
          ListView1.Canvas.Font.Color := clBlack;
            ListView1.Canvas.Font.Name :='仿宋体';
        end;
      end;
    end;