unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TPanel =
class(ExtCtrls.TPanel)
private
{ Private-Deklarationen }
FOnMouseEnter: TNotifyEvent;
FOnMouseLeave: TNotifyEvent;
procedure CMMouseEnter(
var Message: TMessage);
message CM_MOUSEENTER;
procedure CMMouseLeave(
var Message: TMessage);
message CM_MOUSELEAVE;
protected
{ Protected-Deklarationen }
public
property Canvas;
property TabOrder;
property TabStop;
property OnMouseEnter: TNotifyEvent
read FOnMouseEnter
write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent
read FOnMouseLeave
write FOnMouseLeave;
end;
type
TForm1 =
class(TForm)
Panel1: TPanel;
Panel2: TPanel;
procedure FormCreate(Sender: TObject);
private
procedure PanelMouseEnter(Sender: TObject);
procedure PanelMouseLeave(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
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;
procedure TForm1.PanelMouseEnter(Sender: TObject);
begin
if Sender
is TPanel
then
begin
TPanel(Sender).Canvas.Brush.Color:= clRed;
TPanel(Sender).Canvas.TextOut(10, 10, '
MouseEnter');
end;
end;
procedure TForm1.PanelMouseLeave(Sender: TObject);
begin
if Sender
is TPanel
then
begin
TPanel(Sender).Canvas.Brush.Color:= clRed;
TPanel(Sender).Canvas.TextOut(10, 10, '
MouseLeave');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Panel2.OnMouseEnter:= PanelMouseEnter;
Panel2.OnMouseLeave:= PanelMouseLeave;
Caption:= inttostr(Panel2.TabOrder);
end;
end.