Board index » delphi » TreeView: Different hints per node

TreeView: Different hints per node

Does anybody know a simple way to have different hints for different nodes
in a treeview?
The hints are to be different from the text of the treenodes, so I can not
use ToolTips (I think...)

Thanks,

Koen

 

Re:TreeView: Different hints per node


Koen van Dijken <k.van.dij...@wxs.nl> wrote in message
news:85arhl$17318@bornews.borland.com...

Quote
> Does anybody know a simple way to have different hints for different nodes
> in a treeview?
> The hints are to be different from the text of the treenodes, so I can not
> use ToolTips (I think...)

==
I posted this routine about a month and a half ago but didn't get any
response. I never got a chance to work further on the pause problem but it
might be a start for you if no one else offers anything better. Post back
with whatever you come up with.

bobD

Re:TreeView: Different hints per node


I think it was your intention to post the source you made as well. I found
it on Deja News. Thank you. I will surely have a look at it.

Koen

procedure TForm1.MyFormShowHint(var HintStr: string;
                      var CanShow : boolean;
                      var HintInfo : THintInfo);

var
  myNode : TTreeNode;
  treePoint : TPoint;

begin
  if (CanShow and (HintInfo.HintControl = TreeView1)) then
  begin
    treePoint := Treeview1.ScreenToClient(Mouse.CursorPos);
    myNode := TreeView1.GetNodeAt(treePoint.x,treePoint.y);
    if (myNode <> nil ) then
    begin
      //  demo line--replace with actual text source
      HintInfo.HintStr := myNode.Text;
      HintInfo.CursorRect := myNode.DisplayRect(false);
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnShowHint := MyFormShowHint;
end;

BobD <RBDaw...@prodigy.net> schreef in berichtnieuws
85b18t$1...@bornews.borland.com...

Quote

> Koen van Dijken <k.van.dij...@wxs.nl> wrote in message
> news:85arhl$17318@bornews.borland.com...
> > Does anybody know a simple way to have different hints for different
nodes
> > in a treeview?
> > The hints are to be different from the text of the treenodes, so I can
not
> > use ToolTips (I think...)

> ==
> I posted this routine about a month and a half ago but didn't get any
> response. I never got a chance to work further on the pause problem but it
> might be a start for you if no one else offers anything better. Post back
> with whatever you come up with.

> bobD

Re:TreeView: Different hints per node


Bob,

Your code set me on the right track. My solution works fine, also with the
pause you are mentioning.

In this shape, it only works with Delphi 5 because of the TApplicationEvents
component used. You can convert it to previous versions of Delphi by setting
Application.OnShowHint to a proc with the same code as in
ApplicationEvents1ShowHint, but the problem with that is that you can not
have multiple forms with a OnShowHint handler. This is especially
problematic with modeless forms.

I included my code at the bottom.

Koen

========CODE========

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, AppEvnts;

type
  TForm1 = class(TForm)
    TreeView1: TTreeView;
    ApplicationEvents1: TApplicationEvents;
    procedure FormShow(Sender: TObject);
    procedure ApplicationEvents1ShowHint(var HintStr: String;
      var CanShow: Boolean; var HintInfo: THintInfo);
  private
    FLastHintNode: TTreeNode;
    FLastHintPos:  TPoint;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormShow(Sender: TObject);
begin
  FLastHintNode := nil;
end;

procedure TForm1.ApplicationEvents1ShowHint(var HintStr: String;
  var CanShow: Boolean; var HintInfo: THintInfo);
var
  Node: TTreeNode;
  P:    TPoint;
begin
  { This proc is only for TreeView1 }
  if HintInfo.HintControl <> TreeView1
  then
    Exit;

  P := HintInfo.CursorPos;

  { Only show hints when mouse at a label }
  if not (htOnLabel in TreeView1.GetHitTestInfoAt( P.X, P.Y ))
  then begin
    CanShow := false;
    Exit
  end;

  { Find out which node }
  Node := TreeView1.GetNodeAt( P.X, P.Y );
  if Node = nil
  then begin
    CanShow := false;
    Exit
  end;

  { Same node as last hint node? }
  if Node = FLastHintNode
  then
    { Yes, display at same position as last time }
    HintInfo.HintPos := FLastHintPos
  else begin
    { No, save for later use. }
    FLastHintPos := HintInfo.HintPos;
    FLastHintNode := Node;
  end;

  { Generated hint (could be from Node.Data) }
  HintInfo.HintStr := Node.Text + ' HINT';

  { Refresh interval }
  HintInfo.ReshowTimeout := 100
end;

end.

========END OF CODE========

BobD <RBDaw...@prodigy.net> schreef in berichtnieuws
85b18t$1...@bornews.borland.com...

Quote

> Koen van Dijken <k.van.dij...@wxs.nl> wrote in message
> news:85arhl$17318@bornews.borland.com...
> > Does anybody know a simple way to have different hints for different
nodes
> > in a treeview?
> > The hints are to be different from the text of the treenodes, so I can
not
> > use ToolTips (I think...)

> ==
> I posted this routine about a month and a half ago but didn't get any
> response. I never got a chance to work further on the pause problem but it
> might be a start for you if no one else offers anything better. Post back
> with whatever you come up with.

> bobD

Other Threads