كود :
Imports System.IO
Public Class Form1
Dim picspath As String = "pics\"
Dim pics As New List(Of Image)
Dim pcount As Integer = 0
Private Function IsValidImage(filename As String) As Boolean
Try
Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(filename)
Catch generatedExceptionName As OutOfMemoryException
' Image.FromFile throws an OutOfMemoryException
' if the file does not have a valid image format or
' GDI+ does not support the pixel format of the file.
'
Return False
End Try
Return True
End Function
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If pcount < 0 Then Exit Sub
pic.Image = pics(pcount)
pcount = Int(Rnd() * pics.Count)
Timer1.Interval = 3000
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dir As New DirectoryInfo(picspath)
For Each fl As FileInfo In dir.GetFiles
If IsValidImage(fl.FullName) Then
pics.Add(Image.FromFile(fl.FullName))
End If
Next
End Sub
End Class
حتى لو لم يعمل المثال المرفق فالكود المكتوب هو كل المطلوب.