问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/2714585/smooth-scroll-with-autoscroll