如何设置ListView.Item.Caption的字体颜色,字体样式和背景颜色? 我在下面的图片中看到的代码不能正常工作。
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;
答案 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;