VB.NET tutorial: Image Viewer Application


Example: Image Viewer Application

Sample Image viewer application

In this example, you will use one command button, one listbox, one picturebox, and one OpenFileDialog. The user will click the button to add images to the listbox. The image will be viewed when it is selected from the listbox.
Public Class Form2
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim result As DialogResult
        'set filter
        OpenFileDialog1.Filter = "JPEG Files (*.jpg)|*.jpg|Bitmap Files(*.bmp)|*.bmp| Gif files(*.gif)|*.gif"
        'Enable multi-file names selection
        OpenFileDialog1.Multiselect = True
        'Open file dialog
        result = OpenFileDialog1.ShowDialog
        If result = DialogResult.OK Then
            For Each filename In OpenFileDialog1.FileNames
                'add selected file names to listbox
        End If
    End Sub
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        'View image in picturebox when a file name was selected from the list
        PictureBox1.Image = Image.FromFile(ListBox1.SelectedItem.ToString)
    End Sub
End Class


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.