title: Resize an image in a PictureBox until it is the size of the original image
body: <p>I want an image within a PictureBox that will adjust automatically depending on the size of the window but, not larger than the original image. While <code>PictureBoxSizeMode.Zoom</code> almost does this, when the PictureBox is larger than the image it causes the image to pixelate. I'm currently executing this code on resize:</p>
  
  <pre><code>if (pBox.Height * pBox.Height &lt; pBox.Image.Width * pBox.Image.Height) pBox.SizeMode = PictureBoxSizeMode.Zoom;
  else pBox.SizeMode = PictureBoxSizeMode.CenterImage;
  </code></pre>
  
  <p>While this works most of the time, occasionally the image won't revert back to zoom:</p>
  
  <p><a href="https://i.stack.imgur.com/tLbaD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tLbaD.png" alt="image still on &#39;CenterImage&#39;"></a>
  <a href="https://i.stack.imgur.com/eEGI2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eEGI2.jpg" alt="full image"></a> </p>
  
  <p>Any better way to go about this?</p>