OpenFileDialog control in VB.NET 2010
This article shows openfiledialog control in VB.NET 2010.
In this article we will learn about the file open dialog control in window application in VB.NET.
OpenFileDialog Control
This control are used to select a file. These are the some common properties of OpenFileDialog control:
File name
Property used to get or set file name selected in the file dialog box.
Filter
Property to used to get or set the current file name filter string which sets the choices that appear in 'Save as file type' or 'Files of type' box.
ShowDialog method
To display the dialog box to the user, call the ShowDialog() method.
For example:
click the OpenFileDialog control from toolbox it will take place below the form and take two control picture box control and button to the form.
Now, double click on the button named openfile in the form and write the following code.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Filter = "All Files|*.*|Image Files|*.jpg;*.gif;*.png;*.bmp"
OpenFileDialog1.ShowDialog()
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
Here,
To dynamically load the images use Image class with FromFile() method.
Now press Ctrl+F5 to run the application.
The below window will appear and we choose an image and than and then click on the button named openfile.the image will display on the form.
Such as
Now select an image and click the button open image will display on the picture box.we select image named two_flower from the open file.