Results 1 to 3 of 3

Thread: Quick TSpeedButton Question...

  1. #1

    Quick TSpeedButton Question...

    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.
    My DGDev forum pascal syntax highlight settings:
    <br />[background=#FFFFFF][comment=#8080FF][normal=#000080]
    <br />[number=#C00000][reserved=#000000][string=#00C000]

  2. #2

    Quick TSpeedButton Question...

    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.
    Ask me about the xcess game development kit

  3. #3

    Quick TSpeedButton Question...

    I ended up extending the TSpeedButton as such, worked beautifully:

    [pascal][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.
    [/pascal]
    My DGDev forum pascal syntax highlight settings:
    <br />[background=#FFFFFF][comment=#8080FF][normal=#000080]
    <br />[number=#C00000][reserved=#000000][string=#00C000]

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •