新建一个form 放上两个 按钮 button1,button2。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
private
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CMMouseEnter(var Msg: TMessage);
var
anObject: TObject;
begin
anObject := TObject(Msg.lParam);
if ((anObject <> nil) and (anObject = Button1)) then
begin
ShowMessage('鼠标进入button1');
end;
end;
procedure TForm1.CMMouseLeave(var Msg: TMessage);
var
anObject: TObject;
begin
anObject := TObject(Msg.lParam);
if ((anObject <> nil) and (anObject = Button2)) then
begin
ShowMessage('鼠标离开button2');
end;
end;
end.