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标志,则当用户在其上按鼠标左键时,

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值