Ben*_*iss 5 delphi gridlines virtualtreeview
我在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.Right,
EmptyRect.Top + (I * DefaultNodeHeight));
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
这里有恒定和变量节点高度的结果:
上面屏幕截图中可见的毛刺(从左侧偏移的线条)只是虚线渲染的结果.如果LineStyle
在虚拟树视图上设置属性,lsSolid
则会看到正确的结果.
归档时间: |
|
查看次数: |
2291 次 |
最近记录: |