Ok jeg fandt nogle gode artikler og har lavet komponentet. Men hver gang jeg assigner et billede siger delphi "stack overflow - restart delphi" og så lukker delphi....hvad er der galt...her er sourcen
unit ImageButton;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TOnMouseEvent = procedure( Msg: TWMMouse ) of object;
TImageButton = class(TImage)
private
bNormal: boolean;
bOver: boolean;
bDown: boolean;
bOnMouseEnter: TOnMouseEvent;
bOnMouseLeave: TOnMouseEvent;
bOnMouseDown: TOnMouseEvent;
bOnMouseUp: TOnMouseEvent;
pPic: TPicture;
pPicOver: TPicture;
pPicDown: TPicture;
procedure SetPic(value: TPicture);
procedure SetPicOver(value: TPicture);
procedure SetPicDown(value: TPicture);
protected
procedure WMMouseEnter(var Msg: TWMMouse); message CM_MOUSEENTER;
procedure WMMouseLeave( var Msg: TWMMouse); message CM_MOUSELEAVE;
procedure WMLButtonUp( var Msg: TWMLButtonUp); message WM_LBUTTONUP;
procedure WMLButtonDown( var Msg: TWMLButtonUp); message WM_LBUTTONDOWN;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Picture: TPicture read pPic write SetPic;
property PictureOver: TPicture read pPicOver write SetPicOver;
property PictureDown: TPicture read pPicDown write SetPicDown;
property OnMouseEnter: TOnMouseEvent read bOnMouseEnter;
property OnMouseLeave: TOnMouseEvent read bOnMouseLeave;
property OnMouseDown: TOnMouseEvent read bOnMouseDown;
property OnMouseUp: TOnMouseEvent read bOnMouseUp;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Decko', [TImageButton]);
end;
constructor TImageButton.Create;
begin
inherited;
pPic:= TPicture.Create;
pPicOver:= TPicture.Create;
pPicDown:= TPicture.Create;
bNormal:= true;
bOver:= false;
bDown:= false;
end;
destructor TImageButton.Destroy;
begin
pPic.Free;
pPicOver.Free;
pPicDown.Free;
inherited;
end;
procedure TImageButton.WMMouseEnter(var Msg: TWMMouse);
begin
bOver:= true;
if bDown then Picture:= pPicDown else Picture:= pPicOver;
if Assigned(bOnMouseEnter) then bOnMouseEnter(Msg);
end;
procedure TImageButton.WMMouseLeave(var Msg: TWMMouse);
begin
bNormal:= true;
Picture:= pPic;
if Assigned(bOnMouseLeave) then bOnMouseLeave(Msg);
end;
procedure TImageButton.WMLButtonDown(var Msg: TWMMouse);
begin
inherited;
bDown:= true;
if bOver then Picture:= pPicDown;
if Assigned(bOnMouseDown) then bOnMouseDown(Msg);
end;
procedure TImageButton.WMLButtonUp(var Msg: TWMMouse);
begin
inherited;
bDown:= true;
if bOver then Picture:= pPicOver;
if Assigned(bOnMouseUp) then bOnMouseUp(Msg);
end;
procedure TImageButton.SetPic(Value: TPicture);
begin
Picture:= Value;
pPic.Assign(Value);
end;
procedure TImageButton.SetPicOver(Value: TPicture);
begin
pPicOver.Assign(Value);
end;
procedure TImageButton.SetPicDown(Value: TPicture);
begin
pPicDown.Assign(Value);
end;
end.
-------------------------------------------------------
Jonas (Decko)
-------------------------------------------------------