本文介绍了当内容减少时,Panel autoscroll clientarea无法正确更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Short version:  If a panel contains an large object, and scrollbars are at non-zero positions, and the object in the panel reduces in size, the panel client area does not update correctly. How can this be fixed?

Detailed version:
I have a PictureBox in a Panel control so that scrollbars can be used when the image is large. The bitmap is large, and the PictureBox has SizeMode set to "Stretch", the panel has AutoScroll set to True. So at the start of the program the bitmap is correctly scaled inside the picturebox.

If I press a button in the program, the Picturebox switches SizeMode=PictureBoxSizeMode.AutoSize. Everything is still good, the bitmap is at true size, scrollbars appear.

Now if I scroll to the bottom of the image, switch back to SizeMode=Stretch (the user wants to see the full image again), the image stretches correctly, however the scrollbar does not disappear, and scrolling up there is a large grey area. It is like the client area does not reduce correctly in the panel when the scrollbars are not in the 0 position.

Note that this only happens if the scrollbars are at non-zero positions.

How can I get the panel client area to update (reduce) correctly when the content of the panel reduces in size?





我尝试了什么:



在图片框上使用刷新和无效不能解决这个问题。



What I have tried:

Using Refresh and Invalidate on the picturebox does not solve this.

推荐答案

panel1.AutoScrollPosition = new Point(0, 0);





如果问题只发生在非零位置,请确保在更改前它处于零位置SizeMode。



我不知道它为什么会起作用,但确实如此,我可以忍受它。



If the problem only happens in non-zero positions, make sure that it is in a zero position before changing the SizeMode.

I don't know why it works, but it does, and I can live with that.


这篇关于当内容减少时,Panel autoscroll clientarea无法正确更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 04:35