unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
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;
TLabel =
class(StdCtrls.TLabel)
private
procedure CMMouseEnter(
var Message: TMessage);
message CM_MOUSEENTER;
procedure CMMouseLeave(
var Message: TMessage);
message CM_MOUSELEAVE;
end;
TImage =
class(ExtCtrls.TImage)
private
procedure CMMouseEnter(
var Message: TMessage);
message CM_MOUSEENTER;
procedure CMMouseLeave(
var Message: TMessage);
message CM_MOUSELEAVE;
end;
TForm1 =
class(TForm)
Panel1: TPanel;
Label1: TLabel;
Image1: TImage;
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;
{ TLabel }
procedure TLabel.CMMouseEnter(
var Message: TMessage);
begin
if Assigned(Parent)
then
Parent.Perform(CM_MOUSEENTER, 0, 0);
end;
procedure TLabel.CMMouseLeave(
var Message: TMessage);
begin
if Assigned(Parent)
then
Parent.Perform(CM_MOUSELEAVE, 0, 0);
end;
{ TImage }
procedure TImage.CMMouseEnter(
var Message: TMessage);
begin
if Assigned(Parent)
then
Parent.Perform(CM_MOUSEENTER, 0, 0);
end;
procedure TImage.CMMouseLeave(
var Message: TMessage);
begin
if Assigned(Parent)
then
Parent.Perform(CM_MOUSELEAVE, 0, 0);
end;
{ TForm1 }
procedure TForm1.PanelOnMouseEnter(Sender: TObject);
begin
TPanel(Sender).Color := clHighlight;
end;
procedure TForm1.PanelOnMouseLeave(Sender: TObject);
begin
TPanel(Sender).Color := clBtnFace;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Panel1.OnMouseEnter := PanelOnMouseEnter;
Panel1.OnMouseLeave := PanelOnMouseLeave;
end;
end.