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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With