Delphi 7 - 处理表单中嵌入框架的 MouseWheel 事件?
你好,我有一个表格,里面有几个框架。
对于某些框架,我希望滚动内容(或至少处理鼠标滚轮事件)。
我已尝试以下操作:
简单地为每个帧分配一个 OnMouseWheel 事件处理程序
覆盖父窗体的 MouseWheel 事件:
procedure TFmReview.MouseWheelHandler(var Message: TMessage);
var Control: TControl;
begin
Control := ControlAtPos(ScreenToClient(SmallPointToPoint(TWMMouseWheel(Message).Pos)), False, True);
if Assigned(Control) and (Control <> ActiveControl) then
begin
ShowMessage(Control.Name);
Message.Result := Control.Perform(CM_MOUSEWHEEL, Message.WParam, Message.LParam);
if Message.Result = 0 then
Control.DefaultHandler(Message);
end else inherited MouseWheelHandler(Message);
end;
不幸的是,两者似乎都不起作用。
- 在情况 1 中,事件永远不会被触发,但父窗体鼠标滚轮处理程序会被触发。
- 在情况 2 中,接收焦点的控件是保存我希望向其发送鼠标滚轮事件的框架的面板。
那么,简单地说,我如何将鼠标滚轮事件定向到鼠标光标所在的最顶层控件(无论光标位于哪个框架/父/窗体等中)?
Hi I have a form with several frames inside.
For some of the frames, i wish to scroll the contents (or at least handle the mousewheel event).
I have tried the following:
Simply assigning a OnMouseWheel event handler for each frame
Overriding the MouseWheel event for the parent form:
procedure TFmReview.MouseWheelHandler(var Message: TMessage);
var Control: TControl;
begin
Control := ControlAtPos(ScreenToClient(SmallPointToPoint(TWMMouseWheel(Message).Pos)), False, True);
if Assigned(Control) and (Control <> ActiveControl) then
begin
ShowMessage(Control.Name);
Message.Result := Control.Perform(CM_MOUSEWHEEL, Message.WParam, Message.LParam);
if Message.Result = 0 then
Control.DefaultHandler(Message);
end else inherited MouseWheelHandler(Message);
end;
Unfortunately both dont seem to work.
- In case 1, the event is never triggered, however the parent forms mouse wheel handler is triggered.
- In case 2, the control that receives focus is the panel that holds the frame i wish to send the mousewheel event to.
So, put simply, how can i direct the mousewheel event to the top most control that the mouse cursor is over (regardless of which frame/parent/form etc the cursor is in)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将鼠标滚轮处理推迟到
TWinControl
当前鼠标光标在其上,在主框架中覆盖MouseWheelHandler
方法使用如下代码:To postpone mouse wheel handling to a
TWinControl
over which is currently mouse cursor, override in your main frame form theMouseWheelHandler
method using a code like this: