当前位置 : 主页 > 编程语言 > delphi >

delphi – 如何在TVirtualStringTree中以特殊级别绘制背景颜色

来源:互联网 收集:自由互联 发布时间:2021-06-23
我尝试在所有特殊级别的VirtualStringTree中使用backgroundcolor绘制hightline文本.它看起来像所有相同级别的选定节点. 下面的代码不起作用.请有人指点. procedure TMainForm.Tree1PaintText(Sender: TBaseV
我尝试在所有特殊级别的VirtualStringTree中使用backgroundcolor绘制hightline文本.它看起来像所有相同级别的选定节点.
下面的代码不起作用.请有人指点.

procedure TMainForm.Tree1PaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
var  Data: PNodeData;LEVEL:INTEGER;  tree1node,tree4Node: PVirtualNode;
begin 
    Data := Tree1.GetNodeData(Node);
    Level := tree1.GetNodeLevel(node);

 case column of
     0:begin
        if Level = 0 then BEGIN
               TargetCanvas.Font.Style := TargetCanvas.Font.Style + [fsBold];
               TargetCanvas.Font.Color :=CLyellow;
               targetcanvas.Brush.Color :=clgreen;//don't work
               targetcanvas.Brush.Style :=bssolid;     

             END;
            if  Level = 1 then BEGIN
                  TargetCanvas.Font.Color :=CLaqua; 
                  targetcanvas.Brush.Color :=clgreen;
            end;
       end;
VT更快地填充细胞背景,在PrepareCell方法中更具体.因此,尝试设置画布刷为时已晚.尝试从OnBeforeCellPaint事件填充节点矩形:

procedure TForm1.VirtualStringTree1BeforeCellPaint(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(R);
  end;
end;

预习:

网友评论