Disappearing Picturebox images : <p>I was successful in loading an image from a file into a picturebox in visual basic.  Or so i thought.  I had a msgbox in the code and the picture showed up in the picturebox.  take the msgbox out and no picture. Any Ideas? Thanks</p>

<pre><code>    Private Sub DrawImageinSquarePanel(Panelname As PictureBox, ImageFile As String)
    g = Panelname.CreateGraphics() 'creates new graphics element in panel
    Dim newImage As Image = Image.FromFile(ImageFile) ' Create image.
    Dim SquareDim As Integer 'Size of longest dimension in source image

    If newImage.Width &gt; newImage.Height Then
        SquareDim = newImage.Width
    Else
        SquareDim = newImage.Height
    End If

    MsgBox(Panelname.Width &amp; "   " &amp; Panelname.Height) 'the magic msgbox!!

    ' scale factor
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(Panelname.Width / SquareDim)
    Dim ScaleFactor As Single = Panelname.Width / SquareDim

    ' Create rectangle for source and destination image.
    Dim srcRect As New Rectangle(0, 0, newImage.Width, newImage.Height)
    Dim destRect As New Rectangle((Panelname.Width - newImage.Width * ScaleFactor) / 2, (Panelname.Height - newImage.Height * ScaleFactor) / 2, newImage.Width * ScaleFactor, newImage.Height * ScaleFactor)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw image to screen.
    g.DrawImage(newImage, destRect, srcRect, units)


End Sub
</code></pre>
