程序运行效果如下图:

效果实现源码如下:
procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; var DefaultDraw: Boolean);
var
Rect: TRect;
Button: TSpeedButton;
begin
//设置整列颜色
// if SubItem in [5..15] then
// Sender.Canvas.Font.Color := clGreen
// else
// Sender.Canvas.Font.Color := clBlack;
if SubItem in [5..15] then
begin
if Item.SubItems[SubItem - 1] = '有' then
Sender.Canvas.Font.Color :=clBlue //clgreen//cllime
else
Sender.Canvas.Font.Color := clBlack;
end;
if SubItem=13 then
begin
Sender.Canvas.Font.Color := clRed;
end;
end;
该代码段展示了如何在Delphi中自定义绘制TCustomListView的子项,根据SubItem的索引改变字体颜色。如果SubItem在5到15之间且内容为有,则颜色设为蓝色,否则为黑色。当SubItem等于13时,颜色特别设定为红色。

1750

被折叠的 条评论
为什么被折叠?



