自己定义一个类,派生自TCustomBox,然后自绘其中的项目。我现在想让鼠标移到一个项目上的时候让这行变色显示,请问要如何才能捕获此事件?

解决方案 »

  1.   

    根据font.height,pointer(x,y),scrollbox的position计算。
      

  2.   

    onmousemove事件
    ListBox1.ItemAtPos()
      

  3.   

    (*//
    声明:
      本人保证所提供的方法是所知的最好方法
      解答问题纯属公益性质
      所以请不要向我追问
      如果有时间自会关注后续问题
    分析:<NULL>
    问题:如何通过坐标确定TListBox项的序号?
    设计:Zswang
    日期:2002-10-08
    方案:使用TListBox.ItemAtPos()方法
    //*)procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      TListBox(Sender).ItemIndex := TListBox(Sender).ItemAtPos(Point(X, Y), True);
    //  Caption := IntToStr(TListBox(Sender).ItemAtPos(Point(X, Y), True)); //try
    end;
      

  4.   

    procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
      var
         p:tpoint;
      begin
         p.x:=x;
         p.y:=y;
         if listbox1.ItemAtPos(p,true)>-1 then
           showmessage('当前位置'+inttostr(listbox1.itematpos(p,true)));
    end;