delphi - 如何计算用户在 TListView 中滚动的距离,而不是在用户滚动时计算的距离?

标签 delphi

我有一个 TListView ,其中有一些显示工具提示的专门区域。因为我无法通过设计在 TListView 上定义特定区域来显示每个 Subitem 的工具提示以外的内容。

所以我创建了一个结构,其中包含它们的位置以及工具提示(提示)。这部分工作正常。但是,这些位置在 TListView 内相对于其顶部,因此一旦用户滚动,MousePos 仍然引用 TListView 的完整可见部分code>,无论 TListView 滚动到何处。

这是有道理的;但我希望添加用户向下滚动的 Y 坐标。 (我也想对 X 坐标做同样的事情,但这不太相关。)但据我所知,A)TListView 上没有机制来检测这一点并且B) 大多数谈论 TListView 和滚动的指南都是指捕获正在发生的滚动,而不是在我的例子中,在不同的事件期间(在本例中,在鼠标移动)。

那么我如何检测或计算用户在不发生滚动事件时滚动了多远?

最佳答案

有一个机制:ListView.ViewOrigin

Read ViewOrigin to determine the logical origin of the list image. When the list view is not scrolled, ViewOrigin is (0,0). Otherwise, use the x coordinate to determine the number of pixels the view is scrolled horizontally, and the y coordinate to determine the number of pixels the view is scrolled vertically.

var
  Pt: TPoint;
begin
  Pt := ListView1.ViewOrigin;


仅当您的 ListView 采用 vsIconvsSmallIcon View 样式时,此功能才有效。 (您似乎没有提到您正在使用什么 View 样式)。不过,通过这里的简单测试,看起来它也适用于 vsReport 风格。 ViewOrigin.Y 给出与通过 GetScrollInfo 调用检索的 TScrollInfo 的“nPos”完全相同的值。

关于delphi - 如何计算用户在 TListView 中滚动的距离,而不是在用户滚动时计算的距离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18356596/

相关文章:

delphi - 将宽字符串转换为字符串

mysql - dbexpress 的 DBxmys.dll 缺失错误

delphi - 从 TObjectList 中提取一个对象

delphi - Datasnap xe 与 Remobjects DataAbstract

multithreading - 如何使用 TIdNotify

delphi - 如何在 Spring for Delphi 中使用带有 Autowiring 功能的模拟?

delphi - 在 DataModule 上使用函数

delphi - 为什么 Format 拒绝以 XE4 开头的过程地址参数

delphi - 如何使用 "bsSingle"样式滚动和滚动 Delphi 表单?

delphi - 如何在 TouchKeyboard 组件中预选大写锁定