Image viewer in VB.NET
Imports System.IO
Public Class Form1
Dim index As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If bdialog.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Text = bdialog.SelectedPath
index = 0
Me.listbox1.Items.Clear()
For Each Image As String In My.Computer.FileSystem.GetFiles(TextBox1.Text, FileIO.SearchOption.SearchTopLevelOnly) ', "*.gif*", "*.jpg*", "*.bmp*", "*.png*")
Me.listbox1.Items.Add(Image)
index += 1
Next
Button4.Enabled = True
Button5.Enabled = True
Button8.Enabled = True
Button9.Enabled = True
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
End If
If index > 0 Then
listbox1.SelectedIndex = 0
Else
Me.listbox1.Items.Add("folder is empty")
End If
label2.Text = "total number files in this folder are" & index
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
Try
PictureBox1.Load(TextBox1.Text)
Catch ex As Exception
MsgBox("preview not available", MsgBoxStyle.OkOnly)
End Try

End Sub



Private Sub listbox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listbox1.SelectedIndexChanged
TextBox1.Text = listbox1.SelectedItem
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Me.ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PictureBox1.BackColor = Me.ColorDialog1.Color
End If
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
PictureBox1.BackColor = Color.Transparent()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
Try
If listbox1.SelectedIndex < index Then
listbox1.SelectedIndex += 1
PictureBox1.Load(listbox1.SelectedItem)
Else
MsgBox("this is the last image", MsgBoxStyle.OkOnly)
End If
Catch ex As Exception
MsgBox("file cannot be diplayed", MsgBoxStyle.OkOnly)
End Try

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
If listbox1.SelectedIndex > 0 Then

Try
listbox1.SelectedIndex -= 1
PictureBox1.Load(listbox1.SelectedItem)
Catch ex As Exception
MsgBox("file cannot be diplayed", MsgBoxStyle.OkOnly)
End Try
Else
MsgBox("this is the first image", MsgBoxStyle.OkOnly)
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Normal
End Sub
End Class