PRB: Image File Is Locked When You Set the PictureBox Image Property to a File (311754)
The information in this article applies to:
- Microsoft Visual C# .NET (2002)
This article was previously published under Q311754 For a Microsoft Visual Basic .NET version of this article, see 309482.
This article refers to the following Microsoft .NET Framework Class Library namespace:
SYMPTOMS
When you load a PictureBox control with a picture file, the Microsoft Visual Studio .NET 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:
// Make sure that you have added the System.IO namespace.
using System.IO;
// Specify a valid picture file path on your computer.
FileStream fs;
fs = new FileStream("C:\\WINNT\\Web\\Wallpaper\\Fly Away.jpg", FileMode.Open, FileAccess.Read);
pictureBox1.Image = System.Drawing.Image.FromStream(fs);
fs.Close();
STATUSThis behavior is by design.
Modification Type: | Major | Last Reviewed: | 7/24/2002 |
---|
Keywords: | kbCtrl kbprb KB311754 |
---|
|