Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 虚拟StringTree:如何确定节点文本是否完全显示?_Delphi_Virtualtreeview - Fatal编程技术网

Delphi 虚拟StringTree:如何确定节点文本是否完全显示?

Delphi 虚拟StringTree:如何确定节点文本是否完全显示?,delphi,virtualtreeview,Delphi,Virtualtreeview,当TVirtualStreeTree.HintMode=hmTooltip时,当鼠标悬停在节点和列上时,节点文本将成为提示文本,而节点文本未完全显示。但是我必须设置HintMode=hmHint,以便在偶数处理程序中根据当前鼠标光标的位置提供各种提示文本,并且在该HintMode中不会自动生成提示文本 我的问题是如何知道a节点文本是否完全显示,以便知道应该提供节点文本还是空字符串作为提示文本 谢谢。您可以调用TBaseVirtualTree.GetDisplayRect来确定节点的文本边界。根据

当TVirtualStreeTree.HintMode=hmTooltip时,当鼠标悬停在节点和列上时,节点文本将成为提示文本,而节点文本未完全显示。但是我必须设置HintMode=hmHint,以便在偶数处理程序中根据当前鼠标光标的位置提供各种提示文本,并且在该HintMode中不会自动生成提示文本

我的问题是如何知道a节点文本是否完全显示,以便知道应该提供节点文本还是空字符串作为提示文本

谢谢。

您可以调用
TBaseVirtualTree.GetDisplayRect
来确定节点的文本边界。根据
Unclipped
参数,它将为您提供完整或实际的文本宽度
TextOnly
应设置为
True

function IsTreeTextClipped(Tree: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex): Boolean;
var
  FullRect, ClippedRect: TRect;
begin
  FullRect := Tree.GetDisplayRect(Node, Column, True, True);
  ClippedRect := Tree.GetDisplayRect(Node, Column, True, False);
  Result := (ClippedRect.Right - ClippedRect.Left) < (FullRect.Right - FullRect.Left);
end;
函数IsTreeTextClipped(树:TBaseVirtualTree;节点:PVirtualNode;列:TColumnIndex):布尔;
变量
FullRect,ClippedRect:TRect;
开始
FullRect:=Tree.GetDisplayRect(节点、列、True、True);
ClippedRect:=Tree.GetDisplayRect(节点、列、True、False);
结果:=(ClippedRect.Right-ClippedRect.Left)<(FullRect.Right-FullRect.Left);
结束;

请注意,如果尚未初始化节点,则函数将隐式初始化该节点。

您可以使用树控件本身使用的内容。以下是当
hmTooltip
模式生效时,单行节点的
cm\u HintShow
消息处理程序的摘录

NodeRect := GetDisplayRect(HitInfo.HitNode, HitInfo.HitColumn, True, True, True);
BottomRightCellContentMargin := DoGetCellContentMargin(HitInfo.HitNode, HitInfo.HitColumn
, ccmtBottomRightOnly);

ShowOwnHint := (HitInfo.HitColumn > InvalidColumn) and PtInRect(NodeRect, CursorPos) and
  (CursorPos.X <= ColRight) and (CursorPos.X >= ColLeft) and
  (
    // Show hint also if the node text is partially out of the client area.
    // "ColRight - 1", since the right column border is not part of this cell.
    ( (NodeRect.Right + BottomRightCellContentMargin.X) > Min(ColRight - 1, ClientWidth) ) or
    (NodeRect.Left < Max(ColLeft, 0)) or
    ( (NodeRect.Bottom + BottomRightCellContentMargin.Y) > ClientHeight ) or
    (NodeRect.Top < 0)
  );
nodpright:=GetDisplayRect(HitInfo.HitNode,HitInfo.HitColumn,True,True);
BottomRightCellContentMargin:=DoGetCellContentMargin(HitInfo.HitNode,HitInfo.HITCOLLUMN
,ccmtBottomRightOnly);
ShowOwnHint:=(HitInfo.HitColumn>InvalidColumn)和pInrect(nodpright、CursorPos)以及
(CursorPos.X=ColLeft)和
(
//如果节点文本部分超出客户端区域,也显示提示。
//“ColRight-1”,因为右列边框不是此单元格的一部分。
((noddright.Right+BottomRightCellContentMargin.X)>Min(ColRight-1,ClientWidth))或
(左<最大(夹角,0))或
((noddright.Bottom+BottomRightCellContentMargin.Y)>ClientHeight)或
(nod.Top<0)
);
如果
shoownhint
为true,则应将节点的文本作为提示文本返回。否则,将提示文本留空

使用该代码的主要障碍是
DoGetCellContentMargin
受到保护,因此不能直接调用它。您可以编辑源以使其公开,也可以在自己的函数中复制其功能;如果您没有处理OnBeforeCellPaint事件,那么它始终返回(0,0)


hitinfot
数据来自于调用
gethitestinfo

谢谢你,TOndrej,你的代码工作得很好!我尝试了GetDisplayRect,但是我没有注意到我们可以单独使用这个函数来完成这个任务!嗨,罗布,对不起,自从TOndrej的代码运行以来,我没有尝试过这个,谢谢你!