zoukankan      html  css  js  c++  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标志,则当用户在其上按鼠标左键时,
    它将捕获鼠标,直到用户释放鼠标按钮为止。

  • 相关阅读:
    react-redux简单使用
    jQuery——Js与jQuery的相互转换
    移除HTML5 input在type="number"时的上下小箭头
    echarts 5.0 地图
    Vue echarts 设置初始化默认高亮
    echarts 渐变色
    隐藏滚动条css
    echarts 柱状图--圆角
    echarts 气泡图--option
    Vue 圆柱体组件
  • 原文地址:https://www.cnblogs.com/huixch/p/14442209.html
Copyright © 2011-2022 走看看