to seven_918
非常非常的感谢你!
我现在就指望您能帮我解决此问题了,我现在详细的把我的设计目的告诉您:
在一个Form上有若干个TLabel,如
TLabel1,TLabel2,TLabel3......
其中TLabel1.Caption:='Hello',TLabel3.Caption:='Hello',TLabel2.Caption:='test'等等
在软件设计时:程序员设置
TTALabelsEvent.FEnabe:=True;
TTALabelsEvent.ControlType = ctLabel;
TTALabelsEvent.FValue:='Hello';
TTALabelsEvent.DoSomething(Sender:TObject);
begin
ShowMessage('Hello,Hello!');
end;
软件用户者操作的情况是:
只要把鼠标移动到一个TLabel上,如果TLabel的Caption='Hello' 那么
TLabel.Font改变,如变为斜体,如果在TLabel上点击鼠标,那么就显示信息:'Hello,Hello!'
我非常急需,下带改后的代码,请您修改一下,谢谢!
unit UTALabelsEvent;
interface
uses
Windows, Messages, SysUtils, Classes,
AppEvnts,Graphics, StdCtrls,
Forms, Controls, Dialogs;
type
TControlType = (TLabel);
TDoSomething = procedure(Sender:TObject) of Object;
TTALabelsEvent = class(Tcomponent)
private
{ Private declarations }
DES :Boolean;
FEnable :Boolean;
FControlType:TControlType;
FValue:String;
FDoSomething:TDoSomething;
FOnMouseLeave: TNotifyEvent;
FOnMouseEnter: TNotifyEvent;
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
property Enable:boolean read FEnable write FEnable;
property Value:String read FValue write FValue;
property ControlType:TControlType read FControlType write FControlType;
property DoSomething:TDoSomething read FDoSomething write FDoSomething;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('TA', [TTALabelsEvent]);
end;
constructor TTALabelsEvent.Create(AOwner:TComponent);
begin
Inherited Create(AOwner);
if csDesigning in ComponentState then
begin
DES:=True;
end;
end;
destructor TTALabelsEvent.Destroy;
begin
inherited Destroy;
end;
procedure TTALabelsEvent.CMMouseEnter(var Msg:TMessage);
var
anObject:TObject;
begin
if not DES then
begin
inherited;
if Assigned(FOnMouseEnter) then
begin
FOnMouseEnter(Self);
anObject:=TObject(Msg.LParam);
if (anObject<>nil)and(anObject.ClassName='TLabel')then
begin
if Assigned(FDoSomething) then
FDoSomething(Self);
end;
end;
end;
end;
procedure TTALabelsEvent.CMMouseLeave(var Msg:TMessage);
var
anObject:TObject;
begin
if not DES then
begin
inherited;
if Assigned(FOnMouseLeave) then
begin
FOnMouseLeave(Self);
anObject:=TObject(Msg.LParam);
if (anObject<>nil)and(anObject.ClassName='TLabel')then
begin
ShowMessage('离开');
end;
end;
end;
end;
end.