我如何知道何时停止滚动 TScrollBar?

发布于 2024-08-06 19:26:38 字数 208 浏览 6 评论 0原文

我使用过一些带有滚动条的程序,这些程序可以在您拖动“拇指”时更新链接的内容,而其他程序则在您释放鼠标时才会更新。这意味着这里涉及不同类型的 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 技术交流群。

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

发布评论

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

评论(2

得不到的就毁灭 2024-08-13 19:26:38

尝试此代码(使用 Delphi 2009 进行测试),当您跟踪拇指时,它将用随机颜色填充表单客户端区域,并在释放拇指时将其填充为黄色:

procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
  var ScrollPos: Integer);
begin
  Randomize;
  if ScrollCode = scTrack then
    Color := RGB(Random(256), Random(256), Random(256));
  if ScrollCode = scEndScroll then
    Color := clYellow;
end;

TScrollCode 值映射到您可以在 WM_HSCROLLWM_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:

procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
  var ScrollPos: Integer);
begin
  Randomize;
  if ScrollCode = scTrack then
    Color := RGB(Random(256), Random(256), Random(256));
  if ScrollCode = scEndScroll then
    Color := clYellow;
end;

The TScrollCode values map to the WPARAM values that you will find documented for WM_HSCROLL and WM_VSCROLL.

活泼老夫 2024-08-13 19:26:38

当用户拖动拇指时“实时”更新滚动区域的程序正在处理 wm_HScrollwm_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 the wm_HScroll and wm_VScroll messages. Those that only update when the user releases the thumb are handling the sb_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 another sb_ThumbTrack arrives, reset the timer.

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