unit Unit6;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TPaintBox =
class(ExtCtrls.TPaintBox)
private
FOnMouseEnter,
FOnMouseLeave: TNotifyEvent;
procedure CMMouseEnter (
var mMsg : TMessage);
message CM_MouseEnter;
procedure CMMouseLeave (
var mMsg : TMessage);
message CM_MouseLeave;
published
property OnMouseEnter: TNotifyEvent
READ FOnMouseEnter
WRITE FOnMouseEnter;
property OnMouseLeave: TNotifyEvent
READ FOnMouseLeave
WRITE FOnMouseLeave;
end;
TForm6 =
class(TForm)
PaintBox1: TPaintBox;
PaintBox2: TPaintBox;
procedure FormCreate(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
private
procedure MyMouseEnter(Sender: TObject);
procedure MyMouseLeave(Sender: TObject);
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form6: TForm6;
implementation
{$R *.dfm}
{ TPaintBox }
procedure TPaintBox.CMMouseEnter(
var mMsg: TMessage);
begin
inherited;
if Assigned(OnMouseEnter)
then OnMouseEnter(self);
end;
procedure TPaintBox.CMMouseLeave(
var mMsg: TMessage);
begin
if Assigned(OnMouseLeave)
then OnMouseLeave(self);
end;
procedure TForm6.MyMouseEnter(Sender: TObject);
begin
With TPaintbox(Sender)
do
begin
Tag := clLime;
Invalidate;
end;
end;
procedure TForm6.MyMouseLeave(Sender: TObject);
begin
With TPaintbox(Sender)
do
begin
Tag := clRed;
Invalidate;
end;
end;
procedure TForm6.PaintBox1Paint(Sender: TObject);
// ist auch Paintbox2 zugewiesen
begin
With TPaintBox(Sender).Canvas
do
begin
Brush.Color := TPaintBox(Sender).Tag;
Fillrect(TPaintBox(Sender).ClientRect);
end;
end;
procedure TForm6.FormCreate(Sender: TObject);
begin
Paintbox1.OnMouseEnter := MyMouseEnter;
Paintbox1.OnMouseLeave := MyMouseLeave;
Paintbox2.OnMouseEnter := MyMouseEnter;
Paintbox2.OnMouseLeave := MyMouseLeave;
end;
end.