Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 13-Oct-18 8:55am

1 solution

Sorry about that, solved it...

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


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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900