Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListBox long items hints

Tags:

delphi

vcl

There's a ListBox with some long items. These long items are getting beyond the right edge of the ListBox and here comes an idea to show hints for such items when the mouse is over them.

I've found an example: (from http://delphi.about.com/cs/adptips2001/a/bltip0201_4.htm)

procedure TForm1.ListBox1MouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer) ;
var lstIndex : Integer ;
begin
  with ListBox1 do
  begin
   lstIndex:=SendMessage(Handle, LB_ITEMFROMPOINT, 0, MakeLParam(x,y)) ;
   if (lstIndex >= 0) and (lstIndex <= Items.Count) then
     Hint := Items[lstIndex]
   else
     Hint := ''
   end;
  end;

It works, but every time I want to view a hint for another item I have to move my mouse away from the ListBox and then point on another item to see its hint. Is there any way to view hints for every item without moving the mouse away from the ListBox borders?

like image 913
Vlad Avatar asked Jul 04 '09 12:07

Vlad


1 Answers

var fOldIndex: integer = -1;

procedure TForm1.ListBox1MouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer) ;
var lstIndex : Integer ;
begin
  with ListBox1 do
  begin
   lstIndex:=SendMessage(Handle, LB_ITEMFROMPOINT, 0, MakeLParam(x,y)) ;

   // this should do the trick..
   if fOldIndex <> lstIndex then
     Application.CancelHint;
   fOldIndex := lstIndex;

   if (lstIndex >= 0) and (lstIndex <= Items.Count) then
     Hint := Items[lstIndex]
   else
     Hint := ''
   end;
end;
like image 119
utku_karatas Avatar answered Oct 22 '22 07:10

utku_karatas