Sharouni

How to Add MouseLeave Event

Khaled Shagrouni, November 1, 2000

Arabic

Be sure to have an open door to leave.

Delphi Papers

Published in  Delphi3000.com
and in some whwere in Chinees

I don't know what is wrong with mouse leave event that makes Borland not to support it in Delphi controls. Bellow is a small and easy to follow example of how to implement this event in TImage control. Also this example shows how to build a simple Delphi component.

If you are new in Delphi programming please see the following notes:

  • The example is a Pascal unit, you have to save it in a file with the same unit name as MyImg.pas
  • This example can be applied to other controls, so you can replace TImage class with other classes as TLabel or TButton.

 

unit MyImg;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  ExtCtrls;
type
  TMyImage = class(TImage)
  private
    FOnMouseLeave: TNotifyEvent;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  protected
  public
  published
    property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TMyImage]);
end;

procedure TMyImage.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;

end.

 

 

Shagrouni 2001 Khaled Shagrouni  khaled@shagrouni.com