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 に答える