Click here to Skip to main content
13,795,145 members
Rate this:
 
Please Sign up or sign in to vote.
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 13-Oct-18 8:19am
Updated 13-Oct-18 9:55am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.181207.3 | Last Updated 13 Oct 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100