Articles   Members Online: 3
-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
How to display the item text of a TListBox in the hint window of the listbox 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
27-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
82
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I would like to have my hints read the same as the listbox item that the mouse is 
pointing to. How can I do that?

Answer:

Solve 1:

You could use the listboxes OnMOuseMove event together with the ItemAtPos method.

1   
2   procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: 
3   Integer);
4   var
5     item: Integer;
6   begin
7     with Sender as TListbox do
8     begin
9       item := itemAtpos(Point(x, y), true);
10      if item >= 0 then
11      begin
12        if hint <> items[item] then
13        begin
14          hint := items[item];
15          application.cancelhint;
16        end;
17      end;
18    end;
19  end;



Solve 2:

You can use the OnMouseMove event and trap which item is under the cursor.
20  
21  procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: 
22  Integer);
23  var
24    APoint: TPoint;
25    Index: Integer;
26  begin
27    APoint.X := X;
28    APoint.Y := Y;
29    Index := ListBox1.ItemAtPos(APoint, True);
30    if Index >= 0 then
31    begin
32      ListBox1.Hint := ListBox1.Items.Strings[Index];
33    end;
34  end;


If you want to Hint to change when the mouse moves after the hint is originally 
shown, you might want to do something like this:

Set the ShowHint property of the list box to False.

35  
36  procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: 
37  Integer);
38  var
39    APoint: TPoint;
40    Index: Integer;
41    HW: THintWindow;
42    Rec: TRect;
43    sHint: string;
44  begin
45    APoint.X := X;
46    APoint.Y := Y;
47    Index := ListBox1.ItemAtPos(APoint, True);
48    if Index >= 0 then
49    begin
50      HW := THintWindow.Create(nil);
51      try
52        GetCursorPos(APoint);
53        sHint := ListBox1.Items.Strings[Index];
54        Rec.Top := APoint.Y + 20;
55        Rec.Left := APoint.X;
56        Rec.Right := Rec.Left + HW.Canvas.TextWidth(sHint) + 6;
57        Rec.Bottom := Rec.Top + HW.Canvas.TextHeight(sHint) + 4;
58        HW.ActivateHint(Rec, sHint);
59        HW.Refresh;
60        Sleep(1000);
61        HW.ReleaseHandle;
62      finally
63        HW.Free;
64      end;
65    end;
66  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