我想做的是当鼠标进入toolbutton范围后,toolbutton的imageindex改变,离开后又变回原来的状态。请问各位大狭怎么做?

解决方案 »

  1.   

    在他的Parent上判断
    procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if  (x>button1.Left+button1.Width) and (x<button1.Left) and (y>button1.Top+button1.Height) and (y<button1.Top) then
        button1.Caption:='aaaa'
      else
          button1.Caption:='bbbb';
    end;
      

  2.   

    截获:CM_MOUSEENTER,CM_MOUSELEAVE消息。或者是,即便需要判断是不是落在某个区域里,用控件的ClientRect和PtInRect方法配合,还能简单一些。