Populating Picture Box Using OpenFileDialog

the_atom

Active member
Joined
Apr 18, 2007
Messages
26
Programming Experience
Beginner
Can anyone teach me on how to populate PictureBox using OpenFileDialog. Help Pls.:)
 
Here is a sample. OpenFile is a Button, the Click event code is generated by doubleclicking the control. OpenFileDialog1 is the dialog component, FileOk event code is also generated by doubleclicking the component in Designer View.
VB.NET:
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles OpenFileDialog1.FileOk
    PictureBox1.Load(OpenFileDialog1.FileName)
End Sub
 
Private Sub OpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles OpenFile.Click
    OpenFileDialog1.ShowDialog()
End Sub
You might want to read the documentation for OpenFileDialog to learn how to use other properties like Filter for example, that you should use to limit user to only be able to select image files.
 
Perhaps your forum user profile is wrong? Now it says .Net 2.0, if so correct it.
In that case you can also load the image with:
VB.NET:
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
 
Back
Top