救命啊,各位DFW救命啊,谢谢了(50分)

  • 主题发起人 主题发起人 alex三角猫
  • 开始时间 开始时间
A

alex三角猫

Unregistered / Unconfirmed
GUEST, unregistred user!
如何给 TIMAGE 控件 增加 onmouseenter 和 onmouseleave 事件????
请大家帮忙啊,我就这么多分了,全送上
 
实在想要,就给它添个事件啊,有那么难吗?
 
我是菜鸟,请DX们说的明白点啊
 
参照相关的VCL源码来做吧!
 
给你的类比如:
TMyImage=class(TImage);
private
FOnMouseEnter:TNotifyEvent;//具体类型拼写请看书。我可能写错。
FOnMouseLeave:TNotifyEvent;
procedure CMMOUSEENTER(var Msg:TMessage);message CM_MOUSEENTER;
..
然后公布你的新事件属性
published
..property OnMouseEnter:TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
....

procedure TMyImage.CMMOUSEENTER(var Msg:TMssage);
begin
if Assign(FOnMouseEnter) then
FOnMosueEnter;
end;
//手头没有DELPHI。贫印象写的。你参考一下。具体写来调调看。请看HELP中的
Create Custom Component;
 
unit Unit2;

interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;


type
TMybutton = class(Tbutton)
private
FOnClick:TNotifyEvent;
{ Private declarations }
protected
procedure click;override;
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
published
property OnClick : TNotifyEvent read FOnClick write FOnClick ;
{ Published declarations }

end;
TMyChildButton = class(TMyButton)
private
FOnClick:TNotifyEvent;
{ Private declarations }
protected
procedure click;override;
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
published
property OnClick : TNotifyEvent read FOnClick write FOnClick;
{ Published declarations }

end;
procedure Register;

implementation
procedure Register;
begin
RegisterComponents('MyZxy', [TMyButton]);
RegisterComponents('MyZxy', [TMyChildButton]);
end;
constructor TMybutton.create(AOwner:tcomponent);
begin
inherited create(AOwner);
end;

procedure TMybutton.click;
begin
showmessage('父类的CLICK');
if assigned(FOnClick) then OnClick(self);
end;
constructor TMychildbutton.create(AOwner:tcomponent);
begin
inherited create(AOwner);
end;
procedure TMychildbutton.click;
begin
inherited ;
showmessage('子类的CLICK');
//就差下面这句
if assigned(FOnClick) then OnClick(self);
end;
end.
//======================
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
unit2;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
//procedure b2onclick(Sender: TObject);
procedure b2onclick(Sender: TObject);
procedure b4onclick(Sender: TObject);
procedure b3onclick(Sender: TObject);
procedure b1onclick(Sender: TObject);
private
{ Private declarations }
public
B1:TMyButton;
B2,B3,B4:TMyChildButton;
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.FormCreate(Sender: TObject);
begin
b1:=TMyButton.Create (self);
b1.Parent :=self;//这名为什么不能放在with...do中?
//兄弟请告之
with b1 do
begin
left:= 10;
Top:=90;
Width:=100;
Height:=50;
Font.Size:=13;
Caption:='父亲&p';
OnClick := b1onclick;
end;


b2:=TMyChildButton.Create (self);
b2.Parent :=self;//这名为什么不能放在with...do中?
//兄弟请告之
with b2 do
begin
left:= 140;
Top:=90;
Width:=100;
Height:=50;
Font.Size:=13;
Caption:='子类1&c';
end;
b2.OnClick := b2onclick;

b3:=TMyChildButton.Create (self);
b3.Parent :=self;//这名为什么不能放在with...do中?
//兄弟请告之
with b3 do
begin
left:= 10;
Top:=190;
Width:=100;
Height:=50;
Font.Size:=13;
Caption:='子类2&h';
OnClick := b3onclick;
end;
b4:=TMyChildButton.Create (self);
b4.Parent :=self;//这名为什么不能放在with...do中?
//兄弟请告之
with b4 do
begin
left:= 140;
Top:=190;
Width:=100;
Height:=50;
Font.Size:=13;
Caption:='子类3&d';
OnClick := b4onclick;
end;
end;

procedure TForm1.b2onclick(Sender: TObject);
begin
showmessage('实例子类1自己的CLICK');
end;
procedure TForm1.b3onclick(Sender: TObject);
begin
showmessage('实例子类2自己的CLICK');
end;
procedure TForm1.b1onclick(Sender: TObject);
begin
showmessage('实例父亲自己的CLICK');
end;
procedure TForm1.b4onclick(Sender: TObject);
begin

showmessage('实例子类3自己的CLICK');
end;

end.


只能参考一下
 
谢谢各位DX,我试试,请大家继续
 
多人接受答案了。
 

Similar threads

回复
0
查看
1K
不得闲
S
回复
0
查看
857
SUNSTONE的Delphi笔记
S
S
回复
0
查看
783
SUNSTONE的Delphi笔记
S
后退
顶部