I'm trying to write an app in VB where a user can browse their computer, choose some images and have them display in a slideshow. A later feature will include an option for them to write text which will scroll across the screen - I haven't gotten to this yet.
So far, I can allow them to browse their PC and choose each image one by one. I think this could be tedious and would like to just have them be able to browse to a particular folder and any images in this folder would be displayed as a slideshow. For this I'd prob use filters in case of unwanted file formats. I'm unsure how to actually iterare through a folder for each image though. I'd appreciate any pointers. So far my code is as follows:

Imports System.threading
Public Class Form1
    Inherits System.Windows.Forms.Form
  
    Dim bn As Boolean
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.Multiselect = False
        OpenFileDialog1.Filter = "Jpeg|*.jpg|Gif|*.gif|Jpeg|*.jpeg|Bitmap|*.bmp"
        OpenFileDialog1.RestoreDirectory = True
        OpenFileDialog1.Title = "Browse"
        If OpenFileDialog1.ShowDialog <> DialogResult.Cancel Then
            TextBox1.Text = OpenFileDialog1.FileName
        End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
        PictureBox1.Image = Image.FromFile(TextBox1.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ListBox1.Items.Add(TextBox1.Text)
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        PictureBox1.Image = Image.FromFile(ListBox1.SelectedItem)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Application.Exit()
    End Sub

    Sub shows()
        Dim k, s As String
        Dim i As Integer
        For i = 0 To ListBox1.Items.Count - 1
            k = ListBox1.Items.Item(i)
            s = k
            pb1.Image = Image.FromFile(s)
            Thread.Sleep(3000)
        Next
        Exit Sub
    End Sub
    Dim pb1 As New PictureBox
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim crux As New Form
        crux.WindowState = FormWindowState.Maximized
        crux.Size = New Size(20, 20)
        crux.MaximizeBox = False
        crux.MinimizeBox = False
        crux.BackColor = Color.Black
        crux.Text = "Almotech Slideshow"
        pb1.Dock = DockStyle.Fill
        pb1.BackColor = Color.Black
        pb1.Size = New Size(30, 30)
        pb1.SizeMode = PictureBoxSizeMode.StretchImage
        pb1.BorderStyle = BorderStyle.Fixed3D
        crux.Controls.Add(pb1)
        crux.Show()
        Me.Hide()
        Dim cbz As New Thread(AddressOf shows)
        cbz.Start()
    End Sub

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

End Class

Using a FolderBrowserDialog you can do something like this:

Imports System.IO
'Saves the folder Path in a Text Box
        dlgFolder.SelectedPath = txtFolderPath.Text

        If (dlgFolder.ShowDialog = Windows.Forms.DialogResult.OK) Then
            Dim di As New DriveInfo(dlgFolder.SelectedPath)
            txtFolderPath.Text = dlgFolder.SelectedPath
        End If

                       For Each f As String In Directory.GetFiles(txtFolderPath.Text)
                Dim filename As String = f.Substring(f.LastIndexOf("\") + 1)
                PictureBox1.Image = Image.FromFile(filename .ToString)

            Next

This should work, Its what I used to populate a ListBox with all files from a specified Folder

Cheers
Darren

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.