2

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

4

1 回答 1

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;

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

于 2009-07-28T14:05:42.383 回答