TListView滚动事件

发布于 2024-10-27 11:36:31 字数 68 浏览 4 评论 0原文

TListView 控件是否有一个在控件滚动时触发的事件?

我不想对 TListView 控件进行子类化。

Does the TListView control have an event that will fire whenever the control is scrolled?

I would prefer not to have to sub-class the TListView control.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

望喜 2024-11-03 11:36:31

这工作得很好,但可能违反你的问题的限制。

在包含使用 TListView 的表单的单元的 interface 部分(在 TForm 声明之前),添加

type
  TListView = class(ComCtrls.TListView)
  protected
    procedure WndProc(var Message: TMessage); override;
  end;

Then, 在 同一单元的 >implementation 部分,定义

procedure TListView.WndProc(var Message: TMessage);
begin
  inherited;
  case Message.Msg of
    WM_HSCROLL, WM_VSCROLL: beep;
  end;
end;

This works perfectly, but might violate the constraints of your question.

In the interface section of the unit containing the form that use the TListView (prior to the TForm declaration), add

type
  TListView = class(ComCtrls.TListView)
  protected
    procedure WndProc(var Message: TMessage); override;
  end;

Then, in the implementation section of the same unit, define

procedure TListView.WndProc(var Message: TMessage);
begin
  inherited;
  case Message.Msg of
    WM_HSCROLL, WM_VSCROLL: beep;
  end;
end;
青春有你 2024-11-03 11:36:31

您可以对窗口进行子类化,而无需编写后代类,这在您期望更改的行为是一次性需求时非常有用。编写一个 TWndMethod 函数,如 Andreas的答案,但是将其写在您想要的任何类中,例如拥有列表视图的表单。将其分配给列表视图控件的 WindowProc 财产。在执行此操作之前,请存储该属性的先前值,以便您可以将所有其他消息推迟到它。

type
  TNanikForm = class(TForm)
    ListView: TListView;
  private
    FPrevListViewProc: TWndMethod;
    procedure ListViewWndProc(var Msg: TMessage);
  public
    procedure Loaded; override;
  end;

procedure TNanikForm.ListViewWndProc(var Msg: TMessage);
begin
  case Msg.Message of
    wm_VScroll: ;
    else FPrevListViewProc(Msg);
  end;
end;

procedure TNanikForm.Loaded;
begin
  inherited;
  FPrevListViewProc := ListView.WindowProc;
  ListView.WindowProc := ListViewWndProc;
end;

You can subclass a window without writing a descendant class, which is useful when you expect the changed behavior to be a one-off requirement. Write a TWndMethod function like in Andreas's answer, but write it in whatever class you want, such as the form that owns the list view. Assign it to the list-view control's WindowProc property. Before you do that, store the property's previous value so you can defer all other messages to it.

type
  TNanikForm = class(TForm)
    ListView: TListView;
  private
    FPrevListViewProc: TWndMethod;
    procedure ListViewWndProc(var Msg: TMessage);
  public
    procedure Loaded; override;
  end;

procedure TNanikForm.ListViewWndProc(var Msg: TMessage);
begin
  case Msg.Message of
    wm_VScroll: ;
    else FPrevListViewProc(Msg);
  end;
end;

procedure TNanikForm.Loaded;
begin
  inherited;
  FPrevListViewProc := ListView.WindowProc;
  ListView.WindowProc := ListViewWndProc;
end;
哥,最终变帅啦 2024-11-03 11:36:31

或者,如果您只想捕获垂直滚动事件,您可以使用它。代码与 Andreas 发布的几乎相同......

type
  TListView = class(ComCtrls.TListView)
  protected
    procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
  end;

procedure TListView.WMVScroll(var Message: TWMVScroll);
begin
  inherited;
  Beep;
end;

Or if you want to trap just vertical scroll event, you can use this. Code is almost the same as Andreas posted ...

type
  TListView = class(ComCtrls.TListView)
  protected
    procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
  end;

procedure TListView.WMVScroll(var Message: TWMVScroll);
begin
  inherited;
  Beep;
end;
风吹雪碎 2024-11-03 11:36:31

所有答案都很好:-),但我不想创建新的班级孩子。 感谢大家的帮助:-)!


我的解决方案:我使用组件(在 Delphi 7 中)ApplicationEvents 并检查 的更改滚动条位置(GetScrollPos(ListView.Handle, SB_VERT))。

The all answer is fine :-), but I don't wont to create new child of class. Thanks everyone for your help :-)!


My resolution: I use component (in Delphi 7) ApplicationEvents and I check change of ScrollBar position (GetScrollPos(ListView.Handle, SB_VERT)).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文