【问题标题】:How to define that node of TVirtualStringTree is presented on screen?如何定义 TVirtualStringTree 的节点出现在屏幕上?
【发布时间】:2014-03-10 10:27:44
【问题描述】:

很容易检查节点是否可见。但我不知道如何正确定义屏幕上显示的节点。我只能这样:

BottomNode := Tree.BottomNode;
Node := Tree.TopNode;

IdBottomNode := Tree.AbsoluteIndex(BottomNode);

while Tree.AbsoluteIndex(Node) <> IdBottomNode do
begin
  Node := Node.NextSibling;
  if not Assigned(Node) then
    Break;
end;

(代码不检查)

但我认为这是相当粗糙的方式。可能有更准确的方法吗?

【问题讨论】:

    标签: delphi delphi-xe2 virtualtreeview tvirtualstringtree


    【解决方案1】:

    您可以编写如下函数。 Tree 参数指定虚拟树,Node 是您要检查其是否可见的节点,Column 可选参数是列的索引,如果您需要确定该节点是否甚至列在客户端矩形中可见:

    function IsNodeVisibleInClientRect(Tree: TBaseVirtualTree; Node: PVirtualNode;
      Column: TColumnIndex = NoColumn): Boolean;
    begin
      Result := Tree.IsVisible[Node] and
        Tree.GetDisplayRect(Node, Column, False).IntersectsWith(Tree.ClientRect);
    end;
    

    但也许有更直接的方法...

    【讨论】:

    • 谢谢!现在是最好的办法了。
    • 不客气!我做了一个小改动。您不需要在标题中有任何列。但正如我所说,也许有一些现成的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多