unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, StdCtrls, Buttons, XPMan;
{ TBitBtn }
type
TMouseEnterLeaveNotifyEvent = procedure (Sender: TObject; MouseOver: Boolean) of object;
TBitBtn = class(Buttons.TBitBtn)
private
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
public
OnMouseEvent: TMouseEnterLeaveNotifyEvent;
end;
{ TForm1 }
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
ImageList1: TImageList;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure BitBtnMouseChange(Sender: TObject; MouseOver: Boolean);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TBitBtn }
procedure TBitBtn.CMMouseEnter(var Message: TMessage);
begin
if Assigned(OnMouseEvent) then OnMouseEvent(Self,True);
inherited;
end;
procedure TBitBtn.CMMouseLeave(var Message: TMessage);
begin
if Assigned(OnMouseEvent) then OnMouseEvent(Self,False);
inherited;
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
BitBtn1.OnMouseEvent := BitBtnMouseChange;
ImageList1.GetBitmap(BitBtn1.Tag,BitBtn1.Glyph);
BitBtn2.OnMouseEvent := BitBtnMouseChange;
ImageList1.GetBitmap(BitBtn2.Tag,BitBtn2.Glyph);
end;
procedure TForm1.BitBtnMouseChange(Sender: TObject; MouseOver: Boolean);
var
ImageIndex: Integer;
B: TBitmap;
begin
if (Sender is TBitBtn) then
with TBitBtn(Sender) do
begin
B := Glyph;
ImageIndex := Tag;
if MouseOver then
Inc(ImageIndex);
ImageList1.GetBitmap(ImageIndex,B);
Glyph.Assign(B);
end;
end;
end.