【问题标题】:Delphi Mouse wheel event in component组件中的Delphi鼠标滚轮事件
【发布时间】:2010-12-03 03:10:54
【问题描述】:

我想写一个使用鼠标滚轮进行缩放的组件 类似于 Google 地球。

我有一个使用 onMouseWheel 的组件,我有属性 MaxZoom MinZoom 和 Zoom 有一个更好的选择,即 StretchDraw 与位图我试图在表单中获取组件区域的位置

据我所知,我必须找到每个父级,直到找到 tCustomform 并添加所有组件的顶部和剩下的组件以获取对象位置以找到我的对象位置。有没有更好的方法

一旦我有了位置,如果鼠标在我的对象上,我可以从鼠标光标位置缩放地图以及从哪里缩放。

有人看过代码吗

【问题讨论】:

标签: delphi mousewheel


【解决方案1】:

如果你正在编写一个组件,那么你应该尝试在你的组件中覆盖这两个方法:

函数 DoMouseWheelDown( Shift :TShiftState; MousePos :TPoint ) :Boolean;覆盖; 函数 DoMouseWheelUp( Shift :TShiftState; MousePos :TPoint ) :Boolean;覆盖;

它们是 TControl 的受保护动态方法。每当旋转鼠标滚轮时,它们就会被调用。

【讨论】:

    【解决方案2】:

    这取决于您要缩放的内容类型; 我只会在这里发布如何获得轮子移动了多长时间

    关于私有声明

    private
    { Private declarations }
    procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
    WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    

    在创建或任何其他启动过程中

    OnMouseWheel := formMouseWheel; // depends on you 
    

    FormMouseWheel 是这样来的

    procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
    WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    begin
    // your code here 
    // WheelDelta returns you - or + values (in my computer -120 and + 120 ; 
    // It depends on control panel mouse wheel settings)
    
    //   If it is a font make the font size bigger or 
    // if it is a image 
     // strech := true;
    //  increase width and height of the Timage
    //and put them inside a scrollbox
    // 
    end;
    

    我使用 vcl 表单(不在组件内部)检查了它, 如果您想放大,请告诉我们您想放大什么样的内容

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      • 2017-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多