Delphi   发布时间:2022-04-10  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了delphi – ListBox长项提示大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有一个包含一些长项的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,MakeLParam(x,y)) ;
   if (lsTindex >= 0) and (lsTindex <= Items.Count) then
     Hint := Items[lsTindex]
   else
     Hint := ''
   end;
  end;

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

解决方法

var fOldIndex: Integer = -1;

procedure TForm1.ListBox1MouseMove (Sender: TObject; Shift: TShiftState; 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;

大佬总结

以上是大佬教程为你收集整理的delphi – ListBox长项提示全部内容,希望文章能够帮你解决delphi – ListBox长项提示所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。