随便写了一个,只引出了Button.OnClick.在D6下运行通过.
unit ImageButton;
interface
uses
Windows, Messages, SysUtils, Classes,
Controls, ExtCtrls, StdCtrls;
type
TImageButton = class(TWinControl)
private
FImage: TImage;
FButton: TButton;
FOnClick: TNotifyEvent;
protected
procedure ButtonClick(Sender :TObject);
procedure DoClick; virtual;
procedure Resize; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property OnClick: TNotifyEvent read FOnClick write FOnClick;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TImageButton]);
end;
{ TImageButton }
procedure TImageButton.ButtonClick(Sender: TObject);
begin
DoClick;
end;
constructor TImageButton.Create(AOwner: TComponent);
begin
inherited;
Width := 200;
Height := 220;
FImage := TImage.Create(Self);
FImage.Parent := Self;
FImage.SetBounds(0, 0, 200, 200);
FButton := TButton.Create(Self);
FButton.Parent := Self;
FButton.SetBounds(0, 200, 200, 20);
FButton.OnClick := ButtonClick;
end;
destructor TImageButton.Destroy;
begin
FImage.Free;
FButton.Free;
inherited;
end;
procedure TImageButton.DoClick;
begin
if Assigned(FOnClick) then FOnClick(Self);
end;
procedure TImageButton.Resize;
begin
inherited;
if HandleAllocated then begin
FImage.SetBounds(0, 0, Width, Height - 20);
FButton.SetBounds(0, Height - 20, Width, 20);
end;
end;
end.