Tags:
delphi
Hej Forum.
Jeg er igang med en komponent, hvor jeg kan ændre billede, når man klikker på det, og ved MouseEnter - MouseLeave.
Jeg kan godt indsætte forskellige billder i komponenten, men når jeg bevæger musen hen over det, forsvinder det.
Hvad har jeg gjort galt.??
Venlig hilsen
Leif
* * * * * * * * * *
unit AU_ImageButton;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Graphics, ExtCtrls, Forms,
Dialogs;
type
TAU_ImageButton = class(TImage)
private
FImageMouseEnter: TImage;
FImageMouseLeave: TImage;
FImageMouseClick: TImage;
FOnMouseEnter : TMouseEvent;
FOnMouseLeave : TMouseEvent;
procedure SetImageMouseEnter(Value: TImage);
procedure SetImageMouseLeave(Value: TImage);
procedure SetImageMouseClick(Value: TImage);
procedure CMMouseEnter(var msg: TMessage) ; message CM_MOUSEENTER;
procedure CMMouseLeave(var msg: TMessage) ; message CM_MOUSELEAVE;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ImageMouseEnter: TImage read FImageMouseEnter write SetImageMouseEnter;
property ImageMouseLeave: TImage read FImageMouseLeave write SetImageMouseLeave;
property ImageMouseClick: TImage read FImageMouseClick write SetImageMouseClick;
property OnMouseEnter: TMouseEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TMouseEvent read FOnMouseLeave write FOnMouseLeave;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('AU', [TAU_ImageButton]);
end;
constructor TAU_ImageButton.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
Width := 140;
Height := 36;
FImageMouseEnter := TImage.Create(self);
FImageMouseLeave := TImage.Create(self);
FImageMouseClick := TImage.Create(self);
AutoSize := True;
end;
destructor TAU_ImageButton.Destroy;
begin
FImageMouseEnter.Free;
FImageMouseLeave.Free;
FImageMouseClick.Free;
inherited Destroy;
end;
procedure TAU_ImageButton.SetImageMouseEnter(Value : TImage);
begin
if FImageMouseEnter <> value then
begin
FImageMouseEnter.Assign(Value);
end;
end;
procedure TAU_ImageButton.SetImageMouseLeave(Value : TImage);
begin
if FImageMouseLeave <> value then
begin
FImageMouseLeave.Assign(Value);
end;
end;
procedure TAU_ImageButton.SetImageMouseClick(Value : TImage);
begin
if FImageMouseClick <> value then
begin
FImageMouseClick.Assign(Value);
end;
end;
procedure TAU_ImageButton.CMMouseEnter(var msg: TMessage);
begin
Picture := FImageMouseEnter.Picture;
PictureChanged(Self);
end;
procedure TAU_ImageButton.CMMouseLeave(var msg: TMessage);
begin
Picture := FImageMouseLeave.Picture;
Paint;
end;
procedure TAU_ImageButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
Picture := FImageMouseClick.Picture;
Paint;
end;
end.
1 svar postet i denne tråd vises herunder
0 indlæg har modtaget i alt 0 karma
0
Hej Forum.
Jeg har klaret mit lille problem.
I stedet for TImage skulle det være TBitmap.
( klart ikk´)
så det er blevt til:
----
private
FImageMouseEnter: TBitmap;
----
implementation
procedure TAU_ImageButton.CMMouseEnter(var msg: TMessage);
begin
Picture.Bitmap := ImageMouseEnter;
Paint;
end;
Venlig hilsen
Leif