对于Lazarus组件(类似TPanel),我需要一种方法来检测我的组件何时有鼠标输入和鼠标离开。 Delphi为此提供了消息CM_MOUSEENTER
,我需要为Lazarus提供相同的信息。
我怎样才能在Lazarus中为Win / Linux工作?
答案 0 :(得分:5)
Lazarus中的TControl
类使用与Delphi中相同的CM_MOUSEENTER
消息机制。这些消息不使用操作系统'消息系统,但它们通过Perform
方法注入到控制消息处理程序中,因此它们实际上是独立的。
但是,对于组件开发人员和使用者,有专门的方法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;
如果您只是基于TControl
的组件的消费者,该组件没有发布OnMouseEnter
和OnMouseLeave
个事件,那么您可以使用例如拦截类来发布这些事件,或者在拦截器类中使用上面的代码,但是为了建议你这种情况的正确方法需要知道更多关于控件的信息,因为它可能例如由于某种原因,内部打破了所描述的机制。