将字体颜色,字体样式和背景颜色设置为ListView.Item.Caption

时间:2018-01-13 01:57:00

标签: delphi listviewitem

如何设置ListView.Item.Caption的字体颜色,字体样式和背景颜色? 我在下面的图片中看到的代码不能正常工作。

Image

procedure TFMainForm.ListView1CustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
  case SubItem of
    0:
      begin
        Sender.Canvas.Brush.Color := clLime;
        Sender.Canvas.Font.Color := clBlack;
        Sender.Canvas.Font.Style := [FsBOld];
      end;
    1:
      begin
        Sender.Canvas.Brush.Color := clLime;
        Sender.Canvas.Font.Color := clBlack;
        Sender.Canvas.Font.Style := [FsBOld];
      end;
    2:
      begin
        Sender.Canvas.Font.Color := clBlack;
        Sender.Canvas.Font.Style := [FsBOld];
      end;
    3:
      begin
        Sender.Canvas.Font.Color := clBlack;
        Sender.Canvas.Font.Style := [FsBOld];
      end;
    4:
      begin
        Sender.Canvas.Font.Color := clBlack;
        Sender.Canvas.Font.Style := [FsBOld];
      end;
  end;
end;

1 个答案:

答案 0 :(得分:3)

OnCustomDrawSubItem()仅绘制子项目。使用OnCustomDrawItem()绘制项目。

procedure TForm24.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  Sender.Canvas.Brush.Color := clLime;
end;

procedure TForm24.ListView1CustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
  Sender.Canvas.Brush.Color := clYellow;
end;

enter image description here