Pro*_*020 1 mouseenter mouseleave lazarus
我需要一种方法,对于Lazarus组件(类似TPanel)来检测我的组件何时有鼠标输入和鼠标离开.德尔福有CM_MOUSEENTER这方面的消息,我需要拉撒路.
我怎样才能在Lazarus中为Win/Linux工作?
TControlLazarus中的类使用与CM_MOUSEENTERDelphi中相同的消息机制.这些消息不使用操作系统的消息传递系统,但是它们通过该方法注入到控制消息处理程序中Perform,因此它们实际上与plaftorm无关.
但是,对于组件开发人员和使用者,有专用方法,MouseEnter并且MouseLeave在默认实现中调用OnMouseEnter和OnMouseLeave事件.
现在如何使用此通知取决于您所处的情况.如果您正在编写自己的TCustomPanel后代组件,则应覆盖上述方法,如:
type
TMyPanel = class(TCustomPanel)
protected
procedure MouseEnter; override;
procedure MouseLeave; override;
end;
implementation
procedure TMyPanel.MouseEnter;
begin
inherited;
// do your stuff here
end;
procedure TMyPanel.MouseLeave;
begin
inherited;
// do your stuff here
end;
Run Code Online (Sandbox Code Playgroud)
如果您只是TControl不发布OnMouseEnter和OnMouseLeave事件的基于组件的消费者,那么您可以使用例如拦截类来发布这些事件,或者在拦截器类中使用上面的代码,但建议您适当的方式来处理这种情况需要更多地了解控制,因为它可能由于某种原因在内部破坏所描述的机制.