参考以下代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Hemibtn, ExtCtrls;
type
TMyButton = class(TPanel)
procedure wndproc(var Msg : TMessage);override; //wndproc是一个固定的名称
end;
type
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var aaa : TMybutton;
begin
aaa := Tmybutton.Create(self);
aaa.Top :=100;
aaa.Left := 100;
aaa.width := 200;
aaa.height := 200;
aaa.Parent := Form1;
end;
{ TMyButton }
procedure TMyButton.wndproc(var Msg: TMessage);
begin
if (Msg.Msg = CM_MOUSEENTER) then
begin
Color := clBlue;
Caption := '进来了';
end;
if (Msg.Msg = CM_MOUSELEAVE) then
begin
Color := clBtnFace;
Caption := '离开了';
end;
inherited;
// inherited WndProc(Msg);
end;
end.