Delphi:树视图的自定义提示

发布于 2024-11-15 19:02:02 字数 285 浏览 2 评论 0原文

有没有一种快速的方法来为树视图项目的 5 个子项目创建 5 个自定义提示?

我有 TreeView、1 个项目和 5 个子项目。我需要每个子项的特殊提示(第一个子项 - “F1”,第二个 - “F2” 等等)。

我无法将此应用于我的目的: http://delphi.about.com/ od/vclusing/a/treenode_hint.htm

Is there a fast way to create 5 custom hints for 5 SubItems of Item of Tree View?

I have TreeView, 1 Item and 5 SubItems. I need a special hint for each SubItem (for first one - "F1", second one -"F2" and so on).

I can not apply this to my purpose: http://delphi.about.com/od/vclusing/a/treenode_hint.htm?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羅雙樹 2024-11-22 19:02:02

听起来您只想要 OnHint事件:

procedure TMyForm.TreeView1Hint(Sender: TObject; const Node: TTreeNode; var Hint: string);
begin
  Hint := Node.Text;
end;

有时此方法可能有点粗糙,并提供一个您没有明显将鼠标悬停在其上的 Node。如果您想要更多控制,可以使用 GetNodeAtGetHitTestInfoAt

procedure TMyForm.TreeView1Hint(Sender: TObject; const Node: TTreeNode; var Hint: string);
var
  P: TPoint;
  MyNode: TTreeNode;
  HitTestInfo: THitTests;
begin
  P := TreeView1.ScreenToClient(Mouse.CursorPos);
  MyNode := TreeView1.GetNodeAt(P.X, P.Y);
  HitTestInfo := TreeView1.GetHitTestInfoAt(P.X, P.Y) ;
  if htOnItem in HitTestInfo then begin
    Hint := MyNode.Text;
  end else begin
    Hint := '';
  end;
end;

THitTests 的定义如下:

type
  THitTest = (htAbove, htBelow, htNowhere, htOnItem, htOnButton, htOnIcon,
    htOnIndent, htOnLabel, htOnRight, htOnStateIcon, htToLeft, htToRight);
  THitTests = set of THitTest;

如您所见,这为您提供了很多对显示提示的时间和内容进行细粒度控制。

It sounds like you just want the OnHint event:

procedure TMyForm.TreeView1Hint(Sender: TObject; const Node: TTreeNode; var Hint: string);
begin
  Hint := Node.Text;
end;

Sometimes this method can be a bit crude and offer up a Node that you aren't obviously hovering over. If you want more control you can use GetNodeAt and GetHitTestInfoAt:

procedure TMyForm.TreeView1Hint(Sender: TObject; const Node: TTreeNode; var Hint: string);
var
  P: TPoint;
  MyNode: TTreeNode;
  HitTestInfo: THitTests;
begin
  P := TreeView1.ScreenToClient(Mouse.CursorPos);
  MyNode := TreeView1.GetNodeAt(P.X, P.Y);
  HitTestInfo := TreeView1.GetHitTestInfoAt(P.X, P.Y) ;
  if htOnItem in HitTestInfo then begin
    Hint := MyNode.Text;
  end else begin
    Hint := '';
  end;
end;

The definition of THitTests is as follows:

type
  THitTest = (htAbove, htBelow, htNowhere, htOnItem, htOnButton, htOnIcon,
    htOnIndent, htOnLabel, htOnRight, htOnStateIcon, htToLeft, htToRight);
  THitTests = set of THitTest;

As you can see this gives you a lot of fine grained control over when and what you show as a hint.

别念他 2024-11-22 19:02:02

我会设置组件的提示来响应 OnMouseMove (或者为您提供鼠标坐标的其他事件,您可以从中获取鼠标所在的项目 - 我可能弄错了名称,并且在当我没有德尔福时)。

I would set the hint of the component in response to OnMouseMove (or that other event that gives you mouse coordinates, from which you can get the item the mouse is over - I might have mistaken the name and at the moment I have no Delphi with me).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文