终于有人回了.先谢了.
-------
unit luwei;
interface
uses
SysUtils, Classes, Controls, ExtCtrls,Windows,Messages,Graphics;
type
Tluwei = class(TImage)
private
_DefImage :TPicture;
_EnterImage : TPicture;
_DownImage : TPicture;
_UnEableImage :TPicture;
procedure SetPicture(Value: TPicture);
procedure WM_MouseEnter(var message : TMessage);message CM_MOUSEENTER;
procedure WM_MouseLeave(var message : TMessage);message CM_MOUSEleave;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure Click; override;
{ Private declarations }
protected
procedure SetUnEnableImage;
procedure SetEnableImage;
procedure SetDisAble(value : boolean);virtual;
procedure SetEnAble(value : boolean);virtual;
{ Protected declarations }
public
{ Public declarations }
Disable : Boolean;
Enable : Boolean;
Down : Boolean;
Up : Boolean;
constructor Create(AOwner: TComponent); override;
published
property DefaultImage : TPicture read _DefImage Write _DefImage;
property EnterImage : TPicture read _EnterImage Write _EnterImage;
property DownImage : TPicture read _DownImage Write _DownImage;
property UnEnableImage : TPicture read _UnEableImage Write _UnEableImage;
property PEnable : Boolean read Enable write SetEnAble;
property PDisable : Boolean read Disable write SetDisAble default False;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [Tluwei]);
end;
{ Tluwei }
procedure Tluwei.Click;
begin
if Not Disable then Exit;
inherited;
end;
constructor Tluwei.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
_DefImage := TPicture.Create;
_DefImage.OnProgress := Progress;
_DownImage := TPicture.Create;
_DownImage.OnProgress := Progress;
_UnEableImage := TPicture.Create;
_UnEableImage.OnProgress := Progress;
_EnterImage := TPicture.Create;
_EnterImage.OnProgress := Progress;
Height := 24;
Width := 64;
Up := True;
Down := False;
Disable := True;
Enable := True;
end;
procedure Tluwei.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
if Not Disable then Exit;
if PEnable then
begin
SetPicture(_DownImage);
Down := not Down;
Up := False;
end;
inherited;
end;
procedure Tluwei.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
if Not Disable then Exit;
if PEnable then
begin
if Down then
begin
SetPicture(_DefImage);
Down := Not Down;
Up := True;
end;
end;
inherited;
end;
procedure Tluwei.SetDisAble(value: boolean);
begin
Disable := Value;
if Value then
self.SetEnableImage
else
self.SetUnEnableImage;
end;
procedure Tluwei.SetEnAble(value: boolean);
begin
if Not Disable then Exit;
if Value then
self.SetEnableImage
else
self.SetUnEnableImage;
end;
procedure Tluwei.SetEnableImage;
begin
self.SetPicture(_DefImage);
Enable := True;
end;
procedure Tluwei.SetPicture(Value: TPicture);
begin
// self.Picture.LoadFromFile(Value);
self.Picture.Assign(Value);
end;
procedure Tluwei.SetUnEnableImage;
begin
self.SetPicture(_UnEableImage);
Enable := False;
end;
procedure Tluwei.WM_MouseEnter(var message: TMessage);
begin
if Not Disable then Exit;
if PEnable and (Not Down) then
begin
SetPicture(_EnterImage);
end;
end;
procedure Tluwei.WM_MouseLeave(var message: TMessage);
begin
if Not Disable then Exit;
if PEnable then
begin
self.SetEnableImage;
// SetPicture(_DefImage);
end;
end;
end.
我是你这样写的,不行!!!