tags:

views:

307

answers:

1

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:

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?

+4  A: 
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;
utku_karatas
Bingo! Thank you very much!
Vlad