title: How to determine the proper maximum value for scrollbar c# .NET (how does windows do it?)
body: <p><img src="https://i.stack.imgur.com/KP3Cb.jpg" alt="enter image description here"></p>
  
  <p>Before I go into my question, let me explain my setup:  </p>
  
  <p><strong>First:</strong> I have a PictureBox that holds a Bitmap which is generated at runtime. This Bitmap can be different widths but always the same height.  </p>
  
  <p><strong>Second:</strong> PictureBoxes do not support scrolling, therefore, I have the PictureBox docked in a panel. Initially, I had used the panel's autoscroll feature, but abandoned that after I discovered <a href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/e66c675d-dbb8-4a31-849b-df8057a537f7/is-something-wrong-with-the-width-property-of-controls-in-particular-the-picturebox-control?forum=vbgeneral" rel="nofollow noreferrer">through this article</a> that PictureBoxes have a size limit. I also learned that it's better to instead have small PictureBoxes and only draw what needs to be seen instead of the whole image.  </p>
  
  <p><strong>Third:</strong> So I added a HScrollBar, which is fine and dandy, but I can't seem to figure out the math behind how big to make the scroller. I tried setting the maximum of the scrollbar to the length of the bitmap, but as you can see the size of the scroller is much smaller in mine than the one Windows puts in if I use the autoscroll feature.  </p>
  
  <p><strong>My question is, what is the math behind the scroller size and how do I emulate that in my custom scrollbar?</strong></p>
  
  <p>Let me know if my question is unclear and I will try my best to make it more understandable. And thanks in advance for your help!</p>