我是靠谱客的博主 陶醉中心,这篇文章主要介绍java响应鼠标滚轮事件_TGraphicControl如何捕获鼠标滚轮事件(WMMouseWheel),现在分享给大家,希望可以做个参考。

TGraphicControl默认情况下无法捕获鼠标滚轮事件,如果需要处理鼠标滚轮事件可以采用以下方式处理:

1、在CMMouseenter事件中捕获鼠标,以获得后续的鼠标事件处理权

procedure TTestControl.CMMouseenter(var Message: TMessage);

begin

FPrevFocusHwnd := SetFocus(Parent.Handle);

MouseCapture := True;

inherited;

end;

2、在鼠标离开控件区域时释放鼠标

procedure TTestControl.WMMouseMove(var Message: TWMMouseMove);

begin

if MouseCapture and not PtInRect(ClientRect, SmallPointToPoint(Message.Pos)) then

begin

MouseCapture := False;

SetFocus(FPrevFocusHwnd);

end;

inherited;

end;

经过上述方式处理后就可以在TGraphicControl中响应鼠标滚轮事件了(DoMouseWheel、DoMouseWheelDown、DoMouseWheelUp)。

以下是Delphi帮助文件中对属性MouseCapture的说明:

Specifies whether the control has "captured" mouse events.

Use MouseCapture to determine whether a control has captured the mouse. When a control captures the mouse,

all subsequent mouse events go to that control until the user releases the mouse button.

A control captures the mouse when the user drags an item from it. In addition, if the control has the csCaptureMouse flag set in its ControlStyle property,

it captures the mouse when the user presses the left mouse button over it, until the user releases the mouse button.

大意是说:

MouseCapture指定控件是否“捕获”了鼠标事件。

使用MouseCapture确定控件是否捕获了鼠标。当控件捕获鼠标时,所有后续的鼠标事件都将转到该控件,直到用户释放鼠标按钮为止。

控件在用户从中拖动项目时捕获鼠标。此外,如果控件在其ControlStyle属性中设置了csCaptureMouse标志,则当用户在其上按鼠标左键时,

它将捕获鼠标,直到用户释放鼠标按钮为止。

最后

以上就是陶醉中心最近收集整理的关于java响应鼠标滚轮事件_TGraphicControl如何捕获鼠标滚轮事件(WMMouseWheel)的全部内容,更多相关java响应鼠标滚轮事件_TGraphicControl如何捕获鼠标滚轮事件(WMMouseWheel)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部