Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
ow to Implement tooltips in a TListView Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
31-Oct-02
Category
VCL-General
Language
Delphi 3.x
Views
110
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

Is there a possibility to get tooltips in a common TListView component under Delphi 
4.0? I want to display details if the user moves the mouse over an item and wait a 
little (same function like the component names in Delphi, if you move your mouse 
over a component).

Answer:

There is an event handler in Delphi 5, which makes it possible for you to get 
tooltips for each item of a ListView easily: TListView.OnInfoTip. In Delphi 3 and 
4, you have to write your own hint event handler, which you assign to the method 
OnShowHint of TApplication:

1   unit Test_u1;
2   { ... }
3   
4   type
5     TForm1 = class(TForm)
6       ListView1: TListView;
7       { ... }
8     private
9       procedure DisplayHint(var HintStr: string; var CanShow: Boolean; var HintInfo:
10        THintInfo);
11    end;
12  
13    { ... }
14  
15  implementation
16  
17  {$R *.DFM}
18  
19  procedure TForm1.FormCreate(Sender: TObject);
20  var
21    NewItem: TListItem;
22  begin
23    Application.OnShowHint := DisplayHint;
24    { ... }
25  end;
26  
27  procedure TForm1.DisplayHint;
28  var
29    Item: TListItem;
30    Rect: TRect;
31  begin
32    CanShow := true;
33    {Trace the item of ListView1, which is found on the mouse position X, Y.
34  	If the mouse isn't dragged over a item, result will be nil.}
35    Item := ListView1.GetItemAt(HintInfo.CursorPos.X, HintInfo.CursorPos.Y);
36    if Item <> nil then
37    begin
38      Rect := Item.DisplayRect(drBounds); {in coordinates of ListView1!}
39      HintInfo.HintStr := 'Mouse is over Item ' + Item.Caption;
40    end
41    else
42    begin
43      Rect := ActiveControl.ClientRect;
44      HintInfo.HintStr := GetShortHint(TControl(ActiveControl).Hint);
45    end;
46    { Converting into coordinates of screen. }
47    Rect.TopLeft := ActiveControl.ClientToScreen(Rect.TopLeft);
48    Rect.BottomRight := ActiveControl.ClientToScreen(Rect.BottomRight);
49    with HintInfo do
50    begin
51      HintPos.Y := Rect.Top + GetSystemMetrics(SM_CYCURSOR);
52      HintPos.X := Rect.Left + GetSystemMetrics(SM_CXCURSOR);
53      HintMaxWidth := TControl(ActiveControl).ClientWidth;
54      HintColor := clInfoBk;
55      ReshowTimeout := 10;
56      HideTimeout := 100;
57    end;
58  end;
59  
60  end.
61  
62  {BTW: The type THintInfo is used to define the appearance and the function of the 
63  HintWindow:}
64  
65  type
66    THintWindowClass = class of THintWindow;
67  
68    THintInfo = record
69      HintControl: TControl;
70      HintWindowClass: THintWindowClass;
71      HintPos: TPoint;
72      HintMaxWidth: Integer;
73      HintColor: TColor;
74      CursorRect: TRect;
75      CursorPos: TPoint;
76      ReshowTimeout: Integer;
77      HideTimeout: Integer;
78      HintStr: string;
79      HintData: Pointer;
80    end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC