如何检测鼠标在Delphi 6中远离TPanel? [英] How to detect when the mouse move away from a TPanel in Delphi 6?
本文介绍了如何检测鼠标在Delphi 6中远离TPanel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用OnMouseMove事件来检测鼠标指针在TPanel上的位置,有没有办法知道鼠标指针何时移开?
I am using the OnMouseMove event to detect when the mouse pointer is over my TPanel, is there a way to know when the mouse pointer had moved away from it?
我需要面板来改变颜色,当鼠标指针在其上,并返回到原来的颜色,一旦它离开它?
I need the panel to change colour when the mouse pointer is over it and return to its original colour once it moved away from it?
我正在使用Delphi 6由
I am using Delphi 6 by the way.
请帮助。
最好的问候。
推荐答案
另一个解决方案是使用 TrackMouseEvent
来接收 WM_MOUSELEAVE
;
Yet another solution, using TrackMouseEvent
to receive WM_MOUSELEAVE
;
type
TMyPanel = class(TPanel)
private
FMouseTracking: Boolean;
FOnMouseLeave: TNotifyEvent;
procedure WMMouseLeave(var Msg: TMessage); message WM_MOUSELEAVE;
protected
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
published
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
end;
procedure TMyPanel.MouseMove(Shift: TShiftState; X, Y: Integer);
var
mEvnt: TTrackMouseEvent;
begin
inherited;
if not FMouseTracking then begin
mEvnt.cbSize := SizeOf(mEvnt);
mEvnt.dwFlags := TME_LEAVE;
mEvnt.hwndTrack := Handle;
TrackMouseEvent(mEvnt);
FMouseTracking := True;
end;
end;
procedure TMyPanel.WMMouseLeave(var Msg: TMessage);
begin
Msg.Result := 0;
FMouseTracking := False;
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;
这篇关于如何检测鼠标在Delphi 6中远离TPanel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文