(在线等待)我写了一个小控件!!!(代码如下)在它会设计期响应!!请问如何使它在设计期不响应呢? ( 积分: 50 )

  • 主题发起人 主题发起人 iyesno
  • 开始时间 开始时间
I

iyesno

Unregistered / Unconfirmed
GUEST, unregistred user!
(在线等待)我写了一个小控件!!!(代码如下)在它会设计期响应!!请问如何使它在设计期不响应呢?

unit JImage;

interface

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

type
TJImage = class(TImage)
private
{ Private declarations }
FNormalBitmap, FHotBitmap: TBitmap;
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
procedure SetNormalBitmap(Bmp: TBitmap);
procedure SetHotBitmap(Bmp: TBitmap);
public
{ Public declarations }
constructor Create(Owner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property NormalBitmap: TBitmap read FNormalBitmap write SetNormalBitmap;
property HotBitmap: TBitmap read FHotBitmap write SetHotBitmap;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Test', [TJImage]);
end;

constructor TJImage.Create(Owner: TComponent);
begin
inherited;
FNormalBitmap := TBitmap.Create;
FHotBitmap := TBitmap.Create;
end;

destructor TJImage.Destroy;
begin
FNormalBitmap.Free;
FHotBitmap.Free;
inherited;
end;

procedure TJImage.CMMouseEnter(var Msg: TMessage);
begin
//if Assigned(FOnMouseLeave) then FOnMouseLeave(self);

if Assigned(FHotBitmap) then Picture.Assign(FHotBitmap);
end;

procedure TJImage.CMMouseLeave(var Msg: TMessage);
begin
if Assigned(FNormalBitmap) then Picture.Assign(FNormalBitmap);
end;

procedure TJImage.SetNormalBitmap(Bmp: TBitmap);
begin
FNormalBitmap.Assign(Bmp);
// Picture.Assign(FNormalBitmap);
end;

procedure TJImage.SetHotBitmap(Bmp: TBitmap);
begin
FHotBitmap.Assign(Bmp);
end;

end.
 
(在线等待)我写了一个小控件!!!(代码如下)在它会设计期响应!!请问如何使它在设计期不响应呢?

unit JImage;

interface

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

type
TJImage = class(TImage)
private
{ Private declarations }
FNormalBitmap, FHotBitmap: TBitmap;
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
procedure SetNormalBitmap(Bmp: TBitmap);
procedure SetHotBitmap(Bmp: TBitmap);
public
{ Public declarations }
constructor Create(Owner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property NormalBitmap: TBitmap read FNormalBitmap write SetNormalBitmap;
property HotBitmap: TBitmap read FHotBitmap write SetHotBitmap;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Test', [TJImage]);
end;

constructor TJImage.Create(Owner: TComponent);
begin
inherited;
FNormalBitmap := TBitmap.Create;
FHotBitmap := TBitmap.Create;
end;

destructor TJImage.Destroy;
begin
FNormalBitmap.Free;
FHotBitmap.Free;
inherited;
end;

procedure TJImage.CMMouseEnter(var Msg: TMessage);
begin
//if Assigned(FOnMouseLeave) then FOnMouseLeave(self);

if Assigned(FHotBitmap) then Picture.Assign(FHotBitmap);
end;

procedure TJImage.CMMouseLeave(var Msg: TMessage);
begin
if Assigned(FNormalBitmap) then Picture.Assign(FNormalBitmap);
end;

procedure TJImage.SetNormalBitmap(Bmp: TBitmap);
begin
FNormalBitmap.Assign(Bmp);
// Picture.Assign(FNormalBitmap);
end;

procedure TJImage.SetHotBitmap(Bmp: TBitmap);
begin
FHotBitmap.Assign(Bmp);
end;

end.
 
如果你想在设计的时候不响应某段代码,你可以:
if csDesigning in ComponentState then// 在设计时
begin
//不响应
end;
 
不是不行!!!
unit JImage;

interface

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

type
TJImage = class(TImage)
private
{ Private declarations }
FNormalBitmap, FHotBitmap: TBitmap;
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
procedure SetNormalBitmap(Bmp: TBitmap);
procedure SetHotBitmap(Bmp: TBitmap);
public
{ Public declarations }
constructor Create(Owner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property NormalBitmap: TBitmap read FNormalBitmap write SetNormalBitmap;
property HotBitmap: TBitmap read FHotBitmap write SetHotBitmap;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Test', [TJImage]);
end;

constructor TJImage.Create(Owner: TComponent);
begin
inherited;
FNormalBitmap := TBitmap.Create;
FHotBitmap := TBitmap.Create;
end;

destructor TJImage.Destroy;
begin
FNormalBitmap.Free;
FHotBitmap.Free;
inherited;
end;

procedure TJImage.CMMouseEnter(var Msg: TMessage);
begin
//if Assigned(FOnMouseLeave) then FOnMouseLeave(self);
if csDesigning in ComponentState then
begin

end
else
begin
if Assigned(FHotBitmap) then Picture.Assign(FHotBitmap);
end;
end;

procedure TJImage.CMMouseLeave(var Msg: TMessage);
begin
if csDesigning in ComponentState then
begin

end
else
begin
if Assigned(FNormalBitmap) then Picture.Assign(FNormalBitmap);
end;
end;

procedure TJImage.SetNormalBitmap(Bmp: TBitmap);
begin
FNormalBitmap.Assign(Bmp);
// Picture.Assign(FNormalBitmap);
end;

procedure TJImage.SetHotBitmap(Bmp: TBitmap);
begin
FHotBitmap.Assign(Bmp);
end;

end.
 
我都是这样做的,都没有发现问题
 
后退
顶部