【问题标题】:How to do mouse panning on a custom component in Delphi 2009如何在 Delphi 2009 中对自定义组件进行鼠标平移
【发布时间】:2010-11-14 16:57:54
【问题描述】:

我正在使用 D2009。我有一个从 TWinControl 派生的组件,我想在其中添加鼠标平移。我看到有一个新的控件样式 csPannable 和一个新的控件状态 csPanning。我一直在查看 vcl 源以试图弄清楚,但到目前为止我有点迷茫。有谁知道这方面的任何文件?任何建议或链接都​​非常感谢!

【问题讨论】:

    标签: delphi delphi-2009 components mousewheel


    【解决方案1】:

    在定义 TWinControl 的同一单元中,您有 TControl 的实现。查看鼠标事件和过程是如何定义的。您可以尝试在组件中捕获鼠标消息。

    试试这个:

    在私有声明中:

    procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
    procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
    procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;
    

    在实现中你可以做这样的事情

    procedure TPanControl.WMLButtonDown(var Message: TWMLButtonDown);
    begin
      Self.Color := clYellow;
    end;
    
    procedure TPanControl.WMLButtonUp(var Message: TWMLButtonUp);
    begin
      Self.Color := clbtnFace;
    end;
    
    procedure TPanControl.WMMouseMove(var Message: TWMMouseMove);
    var
      State : TKeyboardState;
    begin
      GetKeyboardState(State);
      if ((State[VK_LBUTTON] And $80) <> 0) then begin
        Self.Color := clOlive;
      end;
    end;
    

    测试一些变化。 使用这个简单的代码,您可以捕获鼠标事件。在这些过程中,您可以启动鼠标事件或做一些事情来创建平移效果。

    【讨论】:

    • 如前所述,我正在尝试与内置平移支持接口。
    猜你喜欢
    • 2010-11-23
    • 2012-03-05
    • 1970-01-01
    • 2017-11-15
    • 2011-05-03
    • 2015-01-03
    • 2023-03-19
    • 1970-01-01
    • 2019-08-08
    相关资源
    最近更新 更多