我有TVirtualStringTree,我想根据节点级别更改其节点背景色,如下图所示:
我试过这样做,但它只给出了我所需的行结果:
procedure TForm1.VSTBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
R: TRect;
begin
if CellPaintMode = cpmPaint then
begin
R := Sender.GetDisplayRect(Node, Column, True, False, True);
R.Offset(0, -R.Top);
case Sender.GetNodeLevel(Node) of
0: TargetCanvas.Brush.Color := $0000F9FF;
1: TargetCanvas.Brush.Color := $0000BFFF;
2: TargetCanvas.Brush.Color := $000086FF;
end;
TargetCanvas.FillRect(CellRect);
end;
end;
1条答案
按热度按时间vhipe2zx1#
不确定它是否完全正确,但它给出了良好的结果:
结果: