具有自动滚动功能的平滑滚动

发布于 2024-08-30 06:53:59 字数 234 浏览 6 评论 0原文

我在 Windows 窗体上有一个面板。面板已启用自动滚动。滚动条按其应有的方式显示,并且滚动条通常按其应有的方式运行。

但面板的内容只有在释放鼠标按钮时才会更新。如何使内容随着滚动条的移动而滚动。 (我想复制大多数现代程序(例如文字处理程序和网络浏览器)的滚动行为...移动滚动条,内容也会立即滚动。)

我正在使用 C#、Visual Studio 2008 pro 和 Windows XP-pro。

I have a Panel on a Windows Form. The Panel has autoscroll enabled. The scroll bars appear as they should and the scroll bars generally operate as they should.

But the content of the panel is only updated when the mouse button is released. How can I make the content scroll AS the scroll bar is moved. (I want to duplicate the scroll behavior of most modern programs such as word processors and web browsers... move the scroll bar and the content immediately scrolls as well.)

I am using C#, Visual Studio 2008 pro, and Windows XP-pro.

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

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

发布评论

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

评论(1

巾帼英雄 2024-09-06 06:53:59

最后我在网上找到了一个提示,并且有效。

挂钩面板的滚动事件,并在事件处理程序中放置如下代码:

if (e.ScrollOrientation == ScrollOrientation.VerticalScroll) {
  panel1.VerticalScroll.Value = e.NewValue;
}

其中 e 是传递给事件处理程序的 ScrollEventArgs 对象。

当然,水平方向的代码类似。

我不知道为什么这不是自动的,或者为什么没有至少一个属性来实现它。

I finally found a hint on the web, and it works.

Hook the panel's scroll event, and in the event handler, put code like this:

if (e.ScrollOrientation == ScrollOrientation.VerticalScroll) {
  panel1.VerticalScroll.Value = e.NewValue;
}

where e is the ScrollEventArgs object passed to the event handler.

Similar code for horizontal, of course.

I don't know why this isn't automatic, or why there isn't at least a property to make it happen.

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