调整窗口或容器大小时如何修复滚动条?
目前,在我的应用程序中,我使用 HScrollBar 和 VScrollBar 在大图像中进行平移。显示的图像部分基于滚动条的 Value 属性。但是,当调整 SplitContainer 的大小或调整表单窗口的大小时,滚动条的值不会自动更新,并且可能会在屏幕外呈现某些内容。
此时我注意到,如果您单击滚动条的箭头,它会神奇地修复滚动条。我想知道是否有任何方法可以在 Form_Resize 和 SplitContainer_Resize 事件处理程序中模拟单击滚动条来执行此操作,但我找不到任何内容。
在所有调整大小事件中必须手动调整滚动条的值是缓慢的、丑陋的并且效果不佳。我真的希望滚动条能够在窗口调整大小时自动修复自身,就像单击箭头时一样,但我不确定如何实现。
Currently in my application I am using the HScrollBar and VScrollBar for panning around in a large image. The part of the image that is shown is based on the scrollbar's Value property. However, when resizing the SplitContainer or resizing the form window the scrollbar's Value does not automatically update and it may render something off-screen.
At this point I noticed that if you clicked the scrollbar's arrow it magically fixes the scrollbar. I was wondering if there was any way to simulate clicking the scrollbar to do this in the Form_Resize and SplitContainer_Resize event handlers but I couldn't find anything.
Having to manually adjust the scrollbar's value in all resizing events is slow, ugly, and doesn't work well. I'd really like for the scrollbar to just automatically fix itself when the window resizes like it does when you click its arrow but I'm not sure how.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在表单的调整大小事件处理程序中调用滚动条的
Invalidate()
方法:http://msdn.microsoft.com/en -us/library/system.windows.forms.control.invalidate.aspx
这应该会导致它在调整表单大小后正确重绘。
Try calling the scrollbar's
Invalidate()
method in the form's resize event handler:http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate.aspx
That should cause it to redraw correctly after the form is resized.
使用这样的东西:
Use something like this: