I have a problem on loading image into the visual basic 2005 IDE picture box.
If Visual Basic 6 code goes like this,
Me.PictureBox1.Picture = LoadPicture(sImagePath)
how do i load it in Visual Basic 2005
I have a problem on loading image into the visual basic 2005 IDE picture box.
If Visual Basic 6 code goes like this,
Me.PictureBox1.Picture = LoadPicture(sImagePath)
how do i load it in Visual Basic 2005
How do I load image into the picture box in VB2005
Abbott
kuponutcom
Hi,
The code works fine. But my problem is that if I want to delete the .jpg file while the program is runing, an exception is thrown: "The process cannot access the file 'a.jpg' because it is being used by another process."
My question is: Is there a way to load a picture into a picture box, and allow the picture file to be deleted from disk
Thanks.
mannis
Hi Cyber,
This is one way to do it in vb2005
Dim FilePath As String = "C:\TempPicture.jpg" TryPictureBox1.Image = Image.FromFile(FilePath)
Catch ex As ExceptionMessageBox.Show(ex.Message)
End TryI hope this helps
Abdullah Al-Rasheed
Bob Cohen
Notis
Yes there IS a way to load a picture into a picture box, and allow the picture file to be deleted.
. Here is some code: You need to use the FileStream Class...
(Type this code in your General Declerations:)
Imports
SystemImports
System.IOImports
System.Text(Use this code to read the jpg:)
Dim FileDir
FileDir = "C:\File.jpg" 'This is the path of your jpg"
Dim fs As New FileStream(FileDir, FileMode.Open, FileAccess.Read, FileShare.ReadWrite) 'you can read the file IF there isnt another app that has exclusive Read/Write.
Picture.Image = Image.FromStream(fs) 'put the image from fs into the picture box
fs.Close() 'close the FileStream; Very important
(When you want to delete the jpg file from your computer use this code:)
My.Computer.FileSystem.DeleteFile(FileDir, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin, FileIO.UICancelOption.DoNothing)
Let me know if this helps, although it may be a little late
(ie: date of thread).