如果鼠标不在VirtualTreeView(TVirtualStringTree)上,如何禁用MouseWheel [英] How to disable MouseWheel if mouse is not over VirtualTreeView (TVirtualStringTree)
问题描述
如果将TVirtualStringTree放在焦点上,则默认情况下其行为是正常的-即使鼠标不在控制之下(除非在另一个TVirtualStringTree之上),它也会在鼠标滚轮上滚动.
TVirtualStringTree behaves by default if it is focused - it will scroll on mouse wheel even if mouse is not over control (except if it is over another TVirtualStringTree).
是否有一种快速而优雅的方法来禁用此行为?
Is there a quick and elegant way to disable this behaviour?
我已经使用OnMouseWheel
事件进行了此操作,并通过PtInRect
检查是否Mouse.CursorPos
是否在控件上,但是我觉得有更好的方法可以执行此操作,因为这样我可以为我添加的每个TreeView定义一个新事件,并处理何时使控件集中/不集中,因此我希望必须有更好的方法来禁用它.
I already did this with OnMouseWheel
event and checking with PtInRect
if Mouse.CursorPos
if it is over a control but I have a feeling that there is a better way to do the same because this way I'd have to define a new event for each TreeView I add and also handle when to focus/unfocus the control so I hope there must be a better way to disable this.
很明显,我希望鼠标滚轮功能能够照常工作,但仅当鼠标悬停在VirtualTreeView上时.
So to be clear, I want mousewheel function to work as usual, but only when mouse is over VirtualTreeView.
推荐答案
将TApplicationEvents控件拖放到表单中
Drop down a TApplicationEvents control to the form
在TApplicationEvents onMessage
in TApplicationEvents onMessage
procedure TForm5.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
var
pnt: TPoint;
ctrl: TWinControl;
begin
if Msg.message = WM_MOUSEWHEEL then
begin
if not GetCursorPos(pnt) then Exit;
ctrl := FindVCLWindow(pnt);
if Assigned(ctrl) then
Msg.hwnd := ctrl.Handle;
end;
end;
这篇关于如果鼠标不在VirtualTreeView(TVirtualStringTree)上,如何禁用MouseWheel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!