Hardware Delphi

Title: How To Create An MouseEnter / MouseLeave - Event
Question: This application shows how to create an OnMouseEnter
and an OnMouseLeaveEvent. When you enter/leave a
component it gives the messages CM_MOUSEENTER/CM_MOUSELEAVE.
All you have to do is respond to these messages.
Answer:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, ImgList, Buttons, StdCtrls;
type
TMylabel = class(TLabel)
Constructor Create(AOwner: TComponent); Override;
Destructor Destroy; Override;
Private
Procedure CMMouseEnter(var msg: TMessage); message CM_MOUSEENTER;
Procedure CMMouseLeave(var msg: TMessage); message CM_MOUSELEAVE;
end;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TMylabel }
procedure TMylabel.CMMouseEnter(var msg: TMessage);
begin
inherited;
with TMylabel(self) do
begin
if name = 'testlabel1' then
begin
caption := 'OnMouseEnter1'
end;
if name = 'testlabel2' then
begin
caption := 'OnMouseEnter2'
end;
end;
end;
procedure TMylabel.CMMouseLeave(var msg: TMessage);
begin
inherited;
with TMylabel(self) do
begin
caption := 'Test Label';
end;
end;
constructor TMylabel.Create(AOwner: TComponent);
begin
inherited;
end;
destructor TMylabel.Destroy;
begin
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with TMylabel.create(self) do
begin
parent := self;
left := 10;
top := 10;
caption := 'Test Label1';
Font.Size := 18;
Name := 'testlabel1';
end;
with TMylabel.create(self) do
begin
parent := self;
left := 200;
top := 10;
caption := 'Test Label2';
Font.Size := 18;
Name := 'testlabel2';
end;
end;
end.