Thema: Delphi TPanel

Einzelnen Beitrag anzeigen

Benutzerbild von Jens Schumann
Jens Schumann

Registriert seit: 27. Apr 2003
Ort: Bad Honnef
1.644 Beiträge
 
Delphi 2009 Professional
 
#4

Re: TPanel

  Alt 25. Sep 2003, 15:47
Hallo,
dafür habe ich mir mal einen Nachfahren von TPanel erzeugt.
Für Dich sind hier die Event's OnMouseEnter und OnMouseLeave interessant.
Delphi-Quellcode:
unit CanvasPanel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TCanvasPanel = class(TPanel)
  private
    { Private-Deklarationen}
    fOnEraseBkgnd : TNotifyEvent;
    fOnPaint : TNotifyEvent;
    fMouseEnter : TNotifyEvent;
    fMouseLeave : TNotifyEvent;
  protected
    { Protected-Deklarationen}
  protected
  procedure WMEraseBkgnd (var Message : TMessage); message WM_ERASEBKGND;
  procedure WndProc(var Message : TMessage); override;
  procedure CMMouseEnter(Var Message : TMessage); message CM_MOUSEENTER;
  procedure CMMouseLeave(Var Message : TMessage); message CM_MOUSELEAVE;
 public
    { Public-Deklarationen}
    constructor Create(AOwner : TComponent); override;
    property Canvas;
  published
    { Published-Deklarationen }
    property OnEraseBkgnd : TNotifyEvent read fOnEraseBkgnd write fOnEraseBkgnd;
    property OnPaint : TNotifyEvent read fOnPaint write fOnPaint;
    property OnMouseEnter : TNotifyEvent read fMouseEnter write fMouseEnter;
    property OnMouseLeave : TNotifyEvent read fMouseLeave write fMouseLeave;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Beispiele', [TCanvasPanel]);
end;

procedure TCanvasPanel.CMMouseEnter(var Message: TMessage);
begin
 If Enabled then
   If Assigned(fMouseEnter) then fMouseEnter(Self);
end;

procedure TCanvasPanel.CMMouseLeave(var Message: TMessage);
begin
 If Enabled then
   If Assigned(fMouseLeave) then fMouseLeave(Self);
end;

constructor TCanvasPanel.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  fOnEraseBkgnd:=Nil;
  fOnPaint:=Nil;
end;

procedure TCanvasPanel.WMEraseBkgnd (var Message : TMessage);
begin
  If Assigned(fOnEraseBkgnd) then
    fOnEraseBkgnd(Self);
end;

procedure TCanvasPanel.WndProc(var Message : TMessage);
begin
  Inherited;
  If Message.Msg=WM_Paint then
    begin
    If Assigned(fOnPaint) then
      fOnPaint(Self);
    end;
end;

end.
  Mit Zitat antworten Zitat