Load all images from a folder and display one with a key press

  • Thread starter Thread starter jkexbx
  • Start date Start date
J

jkexbx

Guest
I am trying to write a program that will display all the images in a folder and will run through them automatically or advance to the next one with a button press. I am trying to get the loading and displaying part to work but am stuck. It looks like the images aren't being loaded into the imagelist.

Public Class Form1
Private index As Integer = 0
Sub Form1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles Me.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.S) Then
'PictureBox1.Image = Image.FromFile("C:\Users\jerickson1\Desktop\capture3.png")
'index = ImageList1.Images.Count
' Console.Write(index)
'ImageList1.Images.Add(Image.FromFile("C:\Users\jerickson1\Desktop\capture1.png"))
PictureBox1.Image = ImageList1.Images(5)
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'Dim id As String = "Display"
'Dim folder As String = "C:\Users\jerickson1\Desktop"
'Dim filename As String = System.IO.Path.Combine(folder, id & ".png")
Dim directory As New System.IO.DirectoryInfo("C:\Users\jerickson1\Desktop")
If directory.Exists Then
Dim pngFiles() As System.IO.FileInfo = directory.GetFiles("*.png")
For Each pngfile As System.IO.FileInfo In pngFiles
If pngfile.Exists Then
Dim image = System.Drawing.Image.FromFile(pngfile.FullName)
Using image
ImageList1.Images.Add(image)
End Using
End If
Next
End If


End Sub
End Class

Continue reading...
 
Back
Top