Reputation: 19
I am very new to Visual Basic so please be gentle. :P
I am creating a small application, for basic learning purposes, which will allow a user of the application to update a profile of sorts. This includes, uploading a profile picture, which is then stored in /bin/Debug/Resource and then displayed on their profile in a PictureBox.
I am using the following code, which seems to do just that. However, when I close the application and run it again, the image is not displayed on either PictureBox but is still stored in the designated folder.
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If (Not System.IO.Directory.Exists("Resource")) Then
System.IO.Directory.CreateDirectory("Resource")
End If
Dim OpenFileDialog1 As New OpenFileDialog
With OpenFileDialog1
.CheckFileExists = True
.ShowReadOnly = False
.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"
.FilterIndex = 2
'
If .ShowDialog = DialogResult.OK Then
Dim FName() As String = OpenFileDialog1.FileName.Split("\\")
System.IO.File.Copy(OpenFileDialog1.FileName, "Resource\\" + FName(FName.Length - 1))
PictureBox1.Image = Image.FromFile(.FileName)
Profile.PictureBox1.Image = Image.FromFile(.FileName)
End If
End With
End Sub
Any help that you can provide is greatly appreciated.
Thank you.
Upvotes: 0
Views: 11487
Reputation: 3136
This is what you need to do in order to display the picture.
This code will have to be added to the Load form method.
Dim StoredPath As String = "PathToImage"
IF File.Exists(StoredPath) Then
PictureBox1.Image = Image.FromFile(@StoredPath)
PictureBox1.Refresh()
End if
Upvotes: 0