Delphi提供了两个消息在鼠标进入或离开控件时响应 CM_MOUSEENTER, CM_MOUSELEAVE 窗体也是控件。<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs;<br><br>type<br> TForm1 = class(TForm)<br> private<br> { Private declarations }<br> procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;<br> procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>{ TForm1 }<br><br>procedure TForm1.CMMouseEnter(var Message: TMessage);<br>begin<br> //do anything;<br> { 测试 }<br> Caption := '鼠标进入窗体';<br>end;<br><br>procedure TForm1.CMMouseLeave(var Message: TMessage);<br>begin<br> //do anything;<br> { 测试 }<br> Caption := '鼠标离开窗体';<br>end;<br><br>end.