H
hyh5795
Unregistered / Unconfirmed
GUEST, unregistred user!
我第一次写一个实现当鼠标移进,移出Image控件时实现两张图片转换,
但有点问题,实现不了效果代码如下,请各位高手帮我更正一下,谢谢!
unit IMageMouse;
interface
uses
SysUtils, Classes, Controls, ExtCtrls,Graphics,Windows,QControls,Messages;
type
TIMageMouse = class(TImage)
private
{ Private declarations }
FInPicture:TPicture;
FOutPicture:TPicture;
procedure SetInPicture(const value:TPicture);
procedure SetOutPicture(const value:TPicture);
procedure MouseEnter(var mess:TMessage);message CM_MOUSEENTER;
procedure MouseLeave(var mess:TMessage);message CM_MOUSELEAVE;
protected
{ Protected declarations }
procedure DOPaint(var Mess:TWMPaint);message WM_PAINT;
public
{ Public declarations }
isMouseHere:Boolean;
constructor Create(AOwner:TComponent);override;
destructor Destroy();override;
published
{ Published declarations }
property InPicture:TPicture read FInPicture write SetInPicture;
property OutPicture:TPicture read FOutPicture write SetOutPicture;
end;
procedure Register;
implementation
{ TIMageMouse }
constructor TIMageMouse.Create(AOwner: TComponent);
begin
inherited;
FInPicture :=TPicture.Create;
FOutPicture :=TPicture.Create;
end;
destructor TIMageMouse.Destroy;
begin
FInPicture.Free;
FOutPicture.Free;
FInPicture :=nil;
FOutPicture :=nil;
inherited;
end;
procedure TIMageMouse.DOPaint(var Mess: TWMPaint);
var
rect :TRect;
begin
inherited;
if isMouseHere then
begin
Canvas.StretchDraw(ClientRect,FInPicture.Bitmap)
end
else
Canvas.StretchDraw(ClientRect,FOutPicture.Bitmap);
end;
procedure TIMageMouse.MouseEnter(var mess: TMessage);
begin
isMouseHere :=True;
Repaint();
end;
procedure TIMageMouse.MouseLeave(var mess: TMessage);
begin
isMouseHere :=False;
Repaint();
end;
procedure TIMageMouse.SetInPicture(const value: TPicture);
begin
FInPicture.Assign(value);
end;
procedure TIMageMouse.SetOutPicture(const value: TPicture);
begin
FOutPicture.Assign(value);
end;
procedure Register;
begin
RegisterComponents('Samples', [TIMageMouse]);
end;
end.
但有点问题,实现不了效果代码如下,请各位高手帮我更正一下,谢谢!
unit IMageMouse;
interface
uses
SysUtils, Classes, Controls, ExtCtrls,Graphics,Windows,QControls,Messages;
type
TIMageMouse = class(TImage)
private
{ Private declarations }
FInPicture:TPicture;
FOutPicture:TPicture;
procedure SetInPicture(const value:TPicture);
procedure SetOutPicture(const value:TPicture);
procedure MouseEnter(var mess:TMessage);message CM_MOUSEENTER;
procedure MouseLeave(var mess:TMessage);message CM_MOUSELEAVE;
protected
{ Protected declarations }
procedure DOPaint(var Mess:TWMPaint);message WM_PAINT;
public
{ Public declarations }
isMouseHere:Boolean;
constructor Create(AOwner:TComponent);override;
destructor Destroy();override;
published
{ Published declarations }
property InPicture:TPicture read FInPicture write SetInPicture;
property OutPicture:TPicture read FOutPicture write SetOutPicture;
end;
procedure Register;
implementation
{ TIMageMouse }
constructor TIMageMouse.Create(AOwner: TComponent);
begin
inherited;
FInPicture :=TPicture.Create;
FOutPicture :=TPicture.Create;
end;
destructor TIMageMouse.Destroy;
begin
FInPicture.Free;
FOutPicture.Free;
FInPicture :=nil;
FOutPicture :=nil;
inherited;
end;
procedure TIMageMouse.DOPaint(var Mess: TWMPaint);
var
rect :TRect;
begin
inherited;
if isMouseHere then
begin
Canvas.StretchDraw(ClientRect,FInPicture.Bitmap)
end
else
Canvas.StretchDraw(ClientRect,FOutPicture.Bitmap);
end;
procedure TIMageMouse.MouseEnter(var mess: TMessage);
begin
isMouseHere :=True;
Repaint();
end;
procedure TIMageMouse.MouseLeave(var mess: TMessage);
begin
isMouseHere :=False;
Repaint();
end;
procedure TIMageMouse.SetInPicture(const value: TPicture);
begin
FInPicture.Assign(value);
end;
procedure TIMageMouse.SetOutPicture(const value: TPicture);
begin
FOutPicture.Assign(value);
end;
procedure Register;
begin
RegisterComponents('Samples', [TIMageMouse]);
end;
end.