OnCustomDrawItem イベントを使用して、ListView 項目の背景色とフォント色をカスタマイズしようとしています。ただし、サブアイテムの境界線の色は常に 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 があります。この GAP は、ListView の背景の色です。
Delphi XE2 と OS: Windows 7 ビットを使用しています。