'Programmer: Janet Joy 'Picture view: open and view picture, select folder for slide show Public Class Form1 Private Sub mnuExit_Click(sender As Object, e As EventArgs) Handles mnuExit.Click End End Sub Private Sub mnuOpen_Click(sender As Object, e As EventArgs) Handles mnuOpen.Click Me.OpenFileDialog1.Filter = "All Pictures|*.bmp;*.gif;*.png;*.jpg|JPG|*.jpg|Bitmaps|*.bmp|GIFS|*.gif|PNG|*.png" Me.OpenFileDialog1.FileName = "" Me.OpenFileDialog1.ShowDialog() If Me.OpenFileDialog1.FileName <> "" Then Me.PictureBox1.Load(Me.OpenFileDialog1.FileName) Me.Text = Me.OpenFileDialog1.FileName End If End Sub Private Sub mnuSelectFolder_Click(sender As Object, e As EventArgs) Handles mnuSelectFolder.Click FolderBrowserDialog1.ShowDialog() If FolderBrowserDialog1.SelectedPath <> "" Then Dim selectedDir As New System.IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath) 'finds a list of all files in the folder selected Dim selectedFiles As System.IO.FileInfo() = selectedDir.GetFiles 'information about each file in the selected folder Dim file As System.IO.FileInfo cboPictures.Items.Clear() 'get rid of any pictures from a different folder For Each file In selectedFiles 'file will loop for each file in directory Dim pic As Boolean = False 'we will set pic to true if file is a picture Dim filename As String = file.ToString 'make it a string so that we can use string functions filename = filename.ToLower 'lower changes JPG to jpg so we just check fgor jpg, not both If filename.EndsWith(".bmp") Then pic = True If filename.EndsWith(".gif") Then pic = True If filename.EndsWith(".jpg") Then pic = True If filename.EndsWith(".png") Then pic = True If pic Then cboPictures.Items.Add(filename) 'only add the file if it is a picture format Next If cboPictures.Items.Count > 0 Then cboPictures.SelectedIndex = 0 cboPictures.Visible = True Timer1.Interval = 6000 Timer1.Enabled = True Else cboPictures.Visible = False Timer1.Enabled = False End If End If End Sub Private Sub cboPictures_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPictures.SelectedIndexChanged 'When an item in the combo box is selected, display in picture box Dim pathAndFileName As String = FolderBrowserDialog1.SelectedPath & "\" & cboPictures.Text 'we need both the folder and the filename to load the picture. Me.Text = pathAndFileName PictureBox1.Load(pathAndFileName) End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If cboPictures.Visible Then If cboPictures.SelectedIndex < cboPictures.Items.Count - 1 Then cboPictures.SelectedIndex += 1 'show next picture Else cboPictures.SelectedIndex = 0 'go back to first picture End If End If End Sub End Class