Delphi 7 - 处理表单中嵌入框架的 MouseWheel 事件?

发布于 2024-12-14 09:42:09 字数 907 浏览 1 评论 0原文

你好,我有一个表格,里面有几个框架。

对于某些框架,我希望滚动内容(或至少处理鼠标滚轮事件)。

我已尝试以下操作:

简单地为每个帧分配一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱人如己 2024-12-21 09:42:09

将鼠标滚轮处理推迟到 TWinControl当前鼠标光标在其上,在主框架中覆盖 MouseWheelHandler 方法使用如下代码:

type
  TMainForm = class(TForm)
  private
    procedure MouseWheelHandler(var AMessage: TMessage); override;
  public
    { Public declarations }
  end;

implementation

procedure TMainForm.MouseWheelHandler(var AMessage: TMessage);
var
  Control: TWinControl;
begin
  Control := FindVCLWindow(SmallPointToPoint(TWMMouseWheel(AMessage).Pos));
  if Assigned(Control) then
  begin
    AMessage.Result := Control.Perform(CM_MOUSEWHEEL, AMessage.WParam,
      AMessage.LParam);
    if AMessage.Result = 0 then
      Control.DefaultHandler(AMessage);
  end
  else
    inherited MouseWheelHandler(AMessage);
end;

To postpone mouse wheel handling to a TWinControl over which is currently mouse cursor, override in your main frame form the MouseWheelHandler method using a code like this:

type
  TMainForm = class(TForm)
  private
    procedure MouseWheelHandler(var AMessage: TMessage); override;
  public
    { Public declarations }
  end;

implementation

procedure TMainForm.MouseWheelHandler(var AMessage: TMessage);
var
  Control: TWinControl;
begin
  Control := FindVCLWindow(SmallPointToPoint(TWMMouseWheel(AMessage).Pos));
  if Assigned(Control) then
  begin
    AMessage.Result := Control.Perform(CM_MOUSEWHEEL, AMessage.WParam,
      AMessage.LParam);
    if AMessage.Result = 0 then
      Control.DefaultHandler(AMessage);
  end
  else
    inherited MouseWheelHandler(AMessage);
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文