如何在 TvirualTree 中内联绘制节点?

how to draw nodes inline in TvirualTree?

我目前正在使用 on before paint 在 Tvirtualdrawtree 中绘制一些图像。这是我的绘图代码

procedure TForm2.VDTAniBeforeCellPaint(Sender: TBaseVirtualTree;
  TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
  Data: PAnimeData;
  NewRect: TRect;
  R: TRect;
begin
//
  if not Assigned(Node) then
  begin
    exit;
  end;

  Data := VDTAni.GetNodeData(Node);

  case Column of
    0, 1 ,2, 3, 4, 5, 6, 7:
  begin
  TargetCanvas.Brush.Style := bsClear;
  TargetCanvas.FillRect(CellRect);
  NewRect := ContentRect;
  NewRect.Left := NewRect.Left;
  NewRect.Width := 55;
  NewRect.Height := 55;
  NewRect.Top := NewRect.Top + 2;
  NewRect.Bottom := NewRect.Bottom;

  if Column = 0 then
  begin

    with NewRect do
    begin
      TargetCanvas.StretchDraw( NewRect, Data.FObject.anmigraphic);
    end;

  end;
end;

绘制的图像是垂直的。例如,我想水平显示它们,如下图所示

这里是数据结构

type
  TAnmiClass = class
  private
    Fanmigraphic : TGifImage;

  public
    property anmigraphic: TGifImage read Fanmigraphic write Fanmigraphic;

  public
    constructor Create;
    destructor Destroy; override;
  end;

type
  PAnimeData = ^TAnimeData;

  TAnimeData = record
    FObject: TAnmiClass;
  end;

你说:

the images drawn comes vertically

那是因为你只在列为 0 时绘制:

if Column = 0 then
begin
  with NewRect do
  begin
    TargetCanvas.StretchDraw( NewRect, Data.FObject.anmigraphic);
  end;
end;

你没有显示 Data 的结构,但我怀疑你在每个 Data 中都有几张图片。无法从您的代码中确定如何处理不同的图像,因此我仅将该部分显示为一对 <>.

中的伪代码

如果你想在不同的列中绘制不同的图像,我建议这样:

case Column of
  0: TargetCanvas.StretchDraw( NewRect, Data.FObject.anmigraphic);
  1: TargetCanvas.StretchDraw( NewRect, Data.FObject.<reference to second image>);

  7: TargetCanvas.StretchDraw( NewRect, Data.FObject.<reference to eight image>);
end;

而不是上面显示的代码。