Image file is locked when you set the PictureBox Image property to a file (309482)
The information in this article applies to:
- Microsoft Visual Basic 2005 Express Edition
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
This article was previously published under Q309482 For a Microsoft Visual C# .NET version of this article, see 311754.
SYMPTOMS
When you load a PictureBox control with a picture file, the Microsoft Visual Studio .NET or Microsoft Visual Studio 2005 Integrated Development Environment (IDE) maintains a lock on the file. This occurs when you set the Image property of a PictureBox control to a file manually at design time, or when you use the FromFile method at run time.
RESOLUTION
To work around this problem, use the FileStream object as follows:
Dim fs As System.IO.FileStream
' Specify a valid picture file path on your computer.
fs = New System.IO.FileStream("C:\WINNT\Web\Wallpaper\Fly Away.jpg",
IO.FileMode.Open, IO.FileAccess.Read)
PictureBox1.Image = System.Drawing.Image.FromStream(fs)
fs.Close()
STATUSThis behavior is by design.
Modification Type: | Major | Last Reviewed: | 1/25/2006 |
---|
Keywords: | kbtshoot kbvs2005swept kbvs2005applies kbprb KB309482 |
---|
|