Link to home
Start Free TrialLog in
Avatar of fibdev
fibdev

asked on

Toolbar Image swap on mouseover

How do I swap an image when the mouse pointer is over a toolbar button?
ASKER CERTIFIED SOLUTION
Avatar of simonet
simonet
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shenqw
shenqw

First.
  You install the component TSQWToolButton.

Second.
  When you new a Toolbutton then view the Form as Text , Change the ToolButton into TSQWToolButton. If you do that , then you can use the events OnMouseEnter and OnMouseLeave and you can change the Image of the ToolButton.

Good Luck!
shenqw


//TSQWToolButton Component

unit SQWToolButton;

interface

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

type
  TSQWToolButton = class(TToolButton)
  private
    { Private declarations }
    FOnMouseEnter,
    FOnMouseLeave:TNotifyEvent;
  protected
    { Protected declarations }
    procedure CMMouseEnter(var Message:TMessage);message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message:TMessage);message CM_MOUSELEAVE;
  public
    { Public declarations }
  published
    { Published declarations }
    property OnMouseEnter:TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
    property OnMouseLeave:TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TSQWToolButton]);
end;

{ TSQWToolButton }

procedure TSQWToolButton.CMMouseEnter(var Message: TMessage);
begin
  inherited;
  if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
end;

procedure TSQWToolButton.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;

end.
Avatar of fibdev

ASKER

Thanks again Alex,

You the man
Anytime, fibdev. ;)

Alex