unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TPanel =
class(ExtCtrls.TPanel)
private
FOnMouseLeave: TNotifyEvent;
FOnMouseEnter: TNotifyEvent;
procedure CMMouseEnter(
var Message: TMessage);
message CM_MOUSEENTER;
procedure CMMouseLeave(
var Message: TMessage);
message CM_MOUSELEAVE;
public
property OnMouseEnter: TNotifyEvent
read FOnMouseEnter
write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent
read FOnMouseLeave
write FOnMouseLeave;
end;
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
procedure PanelOnMouseEnter(Sender: TObject);
procedure PanelOnMouseLeave(Sender: TObject);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TPanel }
procedure TPanel.CMMouseEnter(
var Message: TMessage);
begin
if Assigned(FOnMouseEnter)
then
FOnMouseEnter(Self);
end;
procedure TPanel.CMMouseLeave(
var Message: TMessage);
begin
if Assigned(FOnMouseLeave)
then
FOnMouseLeave(Self);
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
with TPanel.Create(Self)
do
begin
Parent := Self;
Visible := True;
OnMouseEnter := PanelOnMouseEnter;
OnMouseLeave := PanelOnMouseLeave;
end;
end;
procedure TForm1.PanelOnMouseEnter(Sender: TObject);
begin
TPanel(Sender).Color := clRed;
end;
procedure TForm1.PanelOnMouseLeave(Sender: TObject);
begin
TPanel(Sender).Color := clBlack;;
end;
end.