我如何知道何时停止滚动 TScrollBar?
我使用过一些带有滚动条的程序,这些程序可以在您拖动“拇指”时更新链接的内容,而其他程序则在您释放鼠标时才会更新。这意味着这里涉及不同类型的 Windows 消息。但我从 TScrollBar 中能找到的只是一个 OnScroll 事件,该事件在您拖动时不断触发。它也没有 OnMouseDown 或 OnMouseUp 事件。有没有办法为 TScrollBar 设置“OnEndDragging”通知?
I've used some programs with scroll bars that update the linked content while you're still dragging the "thumb", and others that don't until you release the mouse. This implies that there are different types of Windows messages involved here. But all I can find from TScrollBar is an OnScroll event which fires continually while you're dragging. It also doesn't have a OnMouseDown or OnMouseUp event. Is there any way to set up an "OnEndDragging" notification for a TScrollBar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试此代码(使用 Delphi 2009 进行测试),当您跟踪拇指时,它将用随机颜色填充表单客户端区域,并在释放拇指时将其填充为黄色:
TScrollCode
值映射到您可以在WM_HSCROLL
和WM_VSCROLL
。Try this code (tested with Delphi 2009), it will fill the form client area with a random colour while you track the thumb, and fill it in yellow when the thumb is released:
The
TScrollCode
values map to theWPARAM
values that you will find documented forWM_HSCROLL
andWM_VSCROLL
.当用户拖动拇指时“实时”更新滚动区域的程序正在处理
wm_HScroll
和wm_VScroll
消息。那些仅在用户释放拇指时更新的代码正在处理 sb_ThumbPosition 代码。这两个选项有一个折衷方案,即在用户没有移动拇指一点点后进行更新,即使用户尚未真正释放它。处理
sb_ThumbTrack
,然后设置一个计时器。如果计时器触发,则更新显示。如果另一个 sb_ThumbTrack 到达,则重置计时器。Programs that update their scrolling region "live" as the user drags the thumb are handling the
sb_ThumbTrack
code for thewm_HScroll
andwm_VScroll
messages. Those that only update when the user releases the thumb are handling thesb_ThumbPosition
code.There's a compromise on those two options, which is to update after the user hasn't moved the thumb for a little bit, even if the user hasn't actually released it yet. Handle
sb_ThumbTrack
, and then set a timer. If the timer fires, update the display. If anothersb_ThumbTrack
arrives, reset the timer.