加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 如何为尚不存在的节点显示虚拟树视图网格线?

发布时间:2020-12-15 09:28:16 所属栏目:大数据 来源:网络整理
导读:我在Delphi 7中使用SoftGem的VirtualStringTree. 有没有办法启用完整的网格线(就像在TListView中一样)?我只能找到toShowHorzGridLines,它只显示当前节点的行,而不是下面空白空间中的任何内容,以及toShowVertGridLines,它只显示垂直线. 如何在添加项目之前在
我在Delphi 7中使用SoftGem的VirtualStringTree.

有没有办法启用完整的网格线(就像在TListView中一样)?我只能找到toShowHorzGridLines,它只显示当前节点的行,而不是下面空白空间中的任何内容,以及toShowVertGridLines,它只显示垂直线.

如何在添加项目之前在空白区域中显示它们?

解决方法

我不认为有一种简单的方法可以在不修改PaintTree方法的情况下实现它,因为没有任何节点事件无法触发,因为应该简单绘制线条的节点尚不存在.

这是一种肮脏的方法,如何根据最低可见节点另外绘制水平线.实际上,它在此屏幕截图中绘制了由橙色填充的区域中DefaultNodeHeight值的距离:

这是代码:

type
  TVirtualStringTree = class(VirtualTrees.TVirtualStringTree)
  public
    procedure PaintTree(TargetCanvas: TCanvas; Window: TRect; Target: TPoint;
      PaintOptions: TVTInternalPaintOptions; PixelFormat: TPixelFormat = pfDevice); override;
  end;

implementation

{ TVirtualStringTree }

procedure TVirtualStringTree.PaintTree(TargetCanvas: TCanvas; Window: TRect;
  Target: TPoint; PaintOptions: TVTInternalPaintOptions;
  PixelFormat: TPixelFormat);
var
  I: Integer;
  EmptyRect: TRect;
  PaintInfo: TVTPaintInfo;
begin
  inherited;
  if (poGridLines in PaintOptions) and (toShowHorzGridLines in TreeOptions.PaintOptions) and
    (GetLastVisible <> nil) then
  begin
    EmptyRect := GetDisplayRect(GetLastVisible,Header.Columns[Header.Columns.GetLastVisibleColumn].Index,False);
    EmptyRect := Rect(ClientRect.Left,EmptyRect.Bottom + DefaultNodeHeight,EmptyRect.Right,ClientRect.Bottom);
    ZeroMemory(@PaintInfo,SizeOf(PaintInfo));
    PaintInfo.Canvas := TargetCanvas;
    for I := 0 to ((EmptyRect.Bottom - EmptyRect.Top) div DefaultNodeHeight) do
    begin
      PaintInfo.Canvas.Font.Color := Colors.GridLineColor;
      DrawDottedHLine(PaintInfo,EmptyRect.Left,EmptyRect.Top + (I * DefaultNodeHeight));
    end;
  end;
end;

这里有恒定和变量节点高度的结果:

上面屏幕截图中可见的毛刺(从左侧偏移的线条)只是虚线渲染的结果.如果将虚拟树视图上的LineStyle属性设置为lsSolid,则会看到正确的结果.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读