8

有一个带有一些长项目的 ListBox。这些长项目超出了 ListBox 的右边缘,这里有一个想法,即当鼠标悬停在这些项目上时显示这些项目的提示。

我找到了一个例子:(来自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;

它可以工作,但是每次我想查看另一个项目的提示时,我必须将鼠标从 ListBox 移开,然后指向另一个项目以查看它的提示。有没有办法在不将鼠标移离 ListBox 边框的情况下查看每个项目的提示?

4

1 回答 1

13
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;
于 2009-07-04T15:03:07.747 回答