PDA

View Full Version : Quick TSpeedButton Question...



Xorcist
19-10-2003, 06:38 AM
Why does this control not include MouseEnter/MouseLeave events? And if I wanted to implement them how would I go about doing so... I noticed in the Buttons.pas there are TSpeedButton.CMMouseEnter & TSpeedButton.CMMouseLeave procedures, but I'd rather not stick my code in there.

Harry Hunt
19-10-2003, 07:13 AM
You can just create your own decendant of TSpeedButton and put your code in there. Like TMySpeedButton. CMMouseEnter/MouseLeave ist the way to go.

If you haven't written components before:
Just copy the CMMouseEnter/MouseLeave procedure declarations from Buttons.pas and then create two new properties

property OnMouseEnter: TNotifiyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifiyEvent read FOnMouseLeave write FOnMouseLeave;

then in the CMMouseLeave/Enter procecedures you do this:

if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);


hope that helps.

Xorcist
31-10-2003, 07:38 AM
I ended up extending the TSpeedButton as such, worked beautifully:

[background=#FFFFFF][comment=#8080FF][normal=#000080]
[number=#C00000][reserved=#000000][string=#00C000]
unit ExtSpeedButton;

interface

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

type
TExtSpeedButton = class(Buttons.TSpeedButton)
private
protected
FOnMouseEnter: TNotifyEvent;
FOnMouseLeave: TNotifyEvent;
procedure DoMouseEnter; virtual;
procedure DoMouseLeave; virtual;
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
public
published
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Custom Component', [TExtSpeedButton]);
end;

procedure TExtSpeedButton.DoMouseEnter;
begin
if Assigned(OnMouseEnter) then OnMouseEnter(Self);
end;

procedure TExtSpeedButton.DoMouseLeave;
begin
if Assigned(OnMouseLeave) then OnMouseLeave(Self);
end;

procedure TExtSpeedButton.CMMouseEnter(var Msg: TMessage);
begin
inherited;
DoMouseEnter;
end;

procedure TExtSpeedButton.CMMouseLeave(var Msg: TMessage);
begin
inherited;
DoMouseLeave;
end;

end.