title: Resize PictureBox to match image size
body: <p>How to resize the Picturebox so it can show the full image if the image size is less than monitor size ! I wrote a code which can not resize <em>(but still posting the code)</em>!</p>
  <p>Code before loading image on a button click</p>
  <pre><code>Dim bmp As Bitmap
  bmp = New Bitmap(path)
  If bmp.Width &lt; picBox.Image.Width Then picBox.Width = bmp.Width : If bmp.Height &lt; picBox.Image.Height Then picBox.Height = bmp.Height
  picBox.Invalidate() : picBox.Refresh()
  'picBox.SetBounds(x,y,width,height)
  </code></pre>
  <p>The code does not resize the picturebox, it's just untouched  !</p>
  <h1>Edit</h1>
  <p>The form has the picBox and a groupbox [dock enabled] control only.</p>
  <pre><code>bmp = New Bitmap(dlgOpen.FileName)
  picBox.SizeMode = PictureBoxSizeMode.Normal
  Dim w As Integer = picBox.ClientSize.Width
  Dim h As Integer = picBox.ClientSize.Height
  If bmp.Width &gt; w Then
              w = bmp.Width
  End If
  If bmp.Height &gt; h Then
              h = bmp.Height
  End If
  If w &gt; Me.Width - grpBox.Width Then
              w = Me.Width - grpBox.Width
  End If
  If h &gt; grpBox.Height Then
              h = grpBox.Height
  End If
  picBox.ClientSize = New Size(w, h)
  picBox.ImageLocation = dlgOpen.FileName
  </code></pre>
  <p><em>This code does not re-sizes the picture box either</em> .</p>