如果获得焦点,TVirtualStringTree 的默认行为是 - 即使鼠标未经过控制(除非它位于另一个 TVirtualStringTree 上方),它也会在鼠标滚轮上滚动。
有没有一种快速而优雅的方法来禁用此行为?
我已经使用 OnMouseWheel
事件执行此操作,并使用 PtInRect
检查 Mouse.CursorPos
是否在控件上,但我有一种感觉有一种更好的方法可以做到这一点,因为这样我必须为添加的每个 TreeView 定义一个新事件,并处理何时聚焦/取消聚焦控件,所以我希望必须有更好的方法来禁用它。
所以要明确的是,我希望鼠标滚轮功能照常工作,但仅当鼠标位于 VirtualTreeView 上时才有效。
最佳答案
将 TApplicationEvents 控件下拉到表单
在 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;
关于delphi - 如果鼠标不在 VirtualTreeView (TVirtualStringTree) 上,如何禁用 MouseWheel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8350984/