Solved

PictureBox Not Releasing Image Files

Posted on 2004-10-22
159 Views
Last Modified: 2010-04-23
I am using a PictureBox on an employee information form to display a JPG picture. The form has a combo box on it to switch employees. When I change to the next employee, the previous picture file is not being release. If I try to do anything with it, it says it is in use. Usually after a while it will release on its own. Is there any way to make it release faster?
0
Question by:m9s999
    6 Comments
     
    LVL 8

    Expert Comment

    by:bramsquad
    Me.PictureBox1.Refresh()

    ~b
    0
     

    Author Comment

    by:m9s999
    Refresh didn't help.

    The picturebox is displaying the new picture right away. It is just keeping the previous files open for a while.
    0
     
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    How are you creating an image from the file and displaying it in the PictureBox?

    ~IM
    0
     

    Author Comment

    by:m9s999
    I don't have the code in front of me right now, but I think the syntax i'm using is:
    PictureBox1.Image = Image.FromFile("PathToPicture")
    0
     
    LVL 85

    Accepted Solution

    by:
    You can use code like this to prevent a file lock on the image:

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If OpenFileDialog1.ShowDialog = DialogResult.OK Then
                Dim tempImg As Image = Image.FromFile(OpenFileDialog1.FileName)
                PictureBox1.Image = New Bitmap(tempImg)
                tempImg.Dispose()
            End If
        End Sub

    ~IM
    0
     

    Author Comment

    by:m9s999
    This works. Thanks
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now