上次给别人写的一个组件,是speedbutton的。你改一下吧,不过不知道在d5中有没有效果。
//添加鼠标移入移出事件及图片切换
unit SpeedButtonEx;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Buttons, Graphics;
type
TSpeedButtonEx = class(TSpeedButton)
private
FEnterGlyph: TBitmap;
FLeaveGlyph: TBitmap;
FOnMouseLeave: TNotifyEvent;
FOnMouseEnter: TNotifyEvent;
procedure SetEnterGlyph(Value: TBitmap);
procedure SetLeaveGlyph(Value: TBitmap);
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy;override;
published
property EnterGlyph: TBitmap read FEnterGlyph write SetEnterGlyph; //ÒÆÈëͼƬ
property LeaveGlyph: TBitmap read FLeaveGlyph write SetLeaveGlyph; //ÒƳöͼƬ
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter; //ÒÆÈëʼþ
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave; //ÒƳöʼþ
end;
procedure Register;
implementation
constructor TSpeedButtonEx.Create(AOwner: TComponent);
begin
inherited;
FEnterGlyph := TBitmap.Create;
FLeaveGlyph := TBitmap.Create;
end;
destructor TSpeedButtonEx.Destroy;
begin
FEnterGlyph.Free;
FLeaveGlyph.Free;
inherited;
end;
procedure TSpeedButtonEx.SetEnterGlyph(Value: TBitmap);
begin
FEnterGlyph.Assign(Value);
end;
procedure TSpeedButtonEx.SetLeaveGlyph(Value: TBitmap);
begin
FLeaveGlyph.Assign(Value);
end;
procedure TSpeedButtonEx.CMMouseEnter(var Message: TMessage); //message CM_MOUSEENTER;
begin
if not FEnterGlyph.Empty then
Glyph.Assign(FEnterGlyph);
inherited;
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;
procedure TSpeedButtonEx.CMMouseLeave(var Message: TMessage); //message CM_MOUSELEAVE;
begin
if not FLeaveGlyph.Empty then
Glyph.Assign(FLeaveGlyph);
inherited;
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;
procedure Register;
begin
RegisterComponents('dwh', [TSpeedButtonEx]);
end;
end.