【发布时间】:2012-09-27 13:23:11
【问题描述】:
我正在尝试使用 OnCustomDrawItem 事件自定义 ListView 项目的背景颜色和字体颜色。但是 subitem 的边框颜色始终是 ListView 的背景颜色。有谁知道如何解决这一问题?这是我正在使用的代码:
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
lst: TListView;
i: integer;
f1, f2, c1, c2: TColor;
begin
if (TListView(Sender).ViewStyle = vsIcon) then
Exit;
lst := Sender as TListView;
lst.Canvas.Brush.Style := bsSolid;
i := lst.Items.Count;
if (i mod 2) <> 0 then
begin
c1 := clWhite;
c2 := $00F8F8F8;
f1 := clBlue;
f2 := clBlack;
end else
begin
c1 := $00F8F8F8;
c2 := clWhite;
f1 := clBlack;
f2 := clBlue;
end;
// Painting...
if (Item.Index mod 2) = 0 then
begin
lst.Canvas.Brush.Color := c2;
lst.Canvas.Font.Color := f2;
end else
begin
lst.Canvas.Brush.Color := c1;
lst.Canvas.Font.Color := f1;
end;
end;
编辑:
SubItems 列之间存在间隙。这个 GAP 就是 ListView 的背景颜色。
我使用 Delphi XE2 和操作系统:Windows 7 bit bit。
【问题讨论】:
-
提示:将
(Item.Index mod 2) = 0替换为Odd(Item.Index)(或对最后一条语句的否定)。 -
顺便说一句,子项的列之间有一个间隙……而这个间隙是listview的颜色
-
顺便说一句,我用的是 XE2 和 Win7 64bit
-
确定不是主题?默认情况下,应用程序是主题。也许你以为我在问你是否使用了 VCL 样式。如果您的应用程序没有主题,那么您将不得不删除 comctl32 v6 清单。你这样做了吗?
-
Oppsss.. 那我错了。是的,它是主题。如何从代码中删除此主题?