设计的一个图形组件需要当鼠标离开组件的时候响应一个外部事件,应该如何实现?
解决方案 »
- 向大家推荐一个DELPHI论坛
- ADO批量处理时,CancelBatch为何不能同时取消多条记录?
- 怎么当程序没响应时,程序自已解除
- 请高手指点迷津,分不够还有!救命啊,急!
- 超“急”报表问题
- 请高手们指教?
- 可能各位都没有遇到的问题!sql2000不定期丢失数据!在线等待!分不够可添!急!!!
- 加壳的程序能Hook吗?
- 又一个怪问题。。。。。。。 大虾帮忙
- 如何将编译完成的.chm文件重新转换为网页?先有一个系统是从别人手里接的,其他地方都改好了,只有编译的帮助文件无法修改,请大虾出手
- 启动界面显示时会出现偏移不居中
- 动态生成的一组label,怎么样把label中的文字(长短不定)放在正中间??
FOnMouseLeave: TNotifyEvent;
procedure CMMouseLeave(var Msg:TMessage);message CM_MouseLeave;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;实现procedure TCustomLabel.CMMouseLeave(var Message: TMessage);
begin
inherited;
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;
aiirii(ari-淘金坑) 曾帮过我好多次。
//yeeyeeunit MyImage;interfaceuses
SysUtils, StdCtrls, Classes, Controls, ExtCtrls, Messages, Graphics;const cnstLEFTSTEP=4;
const cnstTOPSTEP=3;type
TMyImage = class(TImage)
private
{ Private declarations }
FMoved:boolean;
FLabel:TLabel;
FOnMouseLeave: TNotifyEvent;
FOnMouseEnter: TNotifyEvent;
procedure SetMoved(const AValue:boolean);
procedure SetLabel(AValue:TLabel); procedure LabelMouseEnter(Sender: TObject);
procedure LabelMouseLeave(Sender: TObject);
protected
{ Protected declarations }
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property YMoved: boolean read FMoved write SetMoved;
property YLabel: TLabel read FLabel write SetLabel;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;//procedure Register;implementation
{
procedure Register;
begin
RegisterComponents('Yeeyee', [TMyImage]);
end;
}
constructor TMyImage.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMoved:=False;
end;procedure TMyImage.SetMoved(const AValue:boolean);
begin
if FMoved<>AValue then
begin
FMoved:=AValue;
end;
end;procedure TMyImage.SetLabel(AValue:TLabel);
begin
if FLabel<>AValue then
begin
FLabel:=AValue;
if Assigned(FLabel) then
begin
FLabel.Left:=Left+(Width-FLabel.Width) div 2;
//FLabel.Top:=Top+Height-FLabel.Height;
FLabel.Top:=Top+Height+FLabel.Height;
FLabel.Font.Name:='宋体';
FLabel.Font.Size:=10;
FLabel.OnMouseEnter:=LabelMouseEnter;
FLabel.OnMouseLeave:=LabelMouseLeave;
end;
end;
end;procedure TMyImage.LabelMouseEnter(Sender: TObject);
begin
if Assigned(FLabel) then
begin
FLabel.Font.Color:=clBlue;
FLabel.Cursor:=crHandPoint; if FMoved then
begin
Left:=Left-cnstLEFTSTEP;
Top:=Top-cnstTOPSTEP;
FLabel.Left:=FLabel.Left-cnstLEFTSTEP;
FLabel.Top:=FLabel.Top-cnstTOPSTEP;
end;
end;
end;procedure TMyImage.LabelMouseLeave(Sender: TObject);
begin
if Assigned(FLabel) then
begin
FLabel.Font.Color:=clBlue;
FLabel.Cursor:=crHandPoint; if FMoved then
begin
Left:=Left+cnstLEFTSTEP;
Top:=Top+cnstTOPSTEP;
FLabel.Left:=FLabel.Left+cnstLEFTSTEP;
FLabel.Top:=FLabel.Top+cnstTOPSTEP;
end;
end;
end;procedure TMyImage.CMMouseEnter(var Message: TMessage);
begin
inherited;
if FMoved then
begin
Left:=Left-cnstLEFTSTEP;
Top:=Top-cnstTOPSTEP;
FLabel.Left:=FLabel.Left-cnstLEFTSTEP;
FLabel.Top:=FLabel.Top-cnstTOPSTEP;
end;
if Assigned(FLabel) then
begin
FLabel.Font.Color:=clBlue;
FLabel.Cursor:=crHandPoint;
end;
Cursor:=crHandPoint;
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;procedure TMyImage.CMMouseLeave(var Message: TMessage);
begin
inherited;
if FMoved then
begin
Left:=Left+cnstLEFTSTEP;
Top:=Top+cnstTOPSTEP;
FLabel.Left:=FLabel.Left+cnstLEFTSTEP;
FLabel.Top:=FLabel.Top+cnstTOPSTEP;
end;
if Assigned(FLabel) then
begin
FLabel.Font.Color:=clWindowText;
FLabel.Cursor:=crDefault;
end;
Cursor:=crDefault;
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;end.
以后还请各位多多关照。