ive created a form that will an unknown amount of populated pictureboxes. I dynamically create as many pictureboxes as i require, problem i have is i need to delete all of the images in a directory (these images populated the pictureboxes).
I have old images from a previous call and i dont want them displayed
Private Sub posterPicClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
'Cast object to get image properties
Dim pic As PictureBox = DirectCast(sender, PictureBox)
Dim posterNo = pic.Name
Dim i = Form1.ListView20.Items.Item(Form1.ListView20.SelectedIndices(0)).Index
'copy poster to movie location
Dim file = "C:\Program Files (x86)\myMovie Manager v3.01\Posters" + "\folder" + posterNo.ToString + ".jpg"
'Delete old posters before fetching the new ones, dipose of image objects first to
'release from memory before deleting
For Each ctl As Control In Me.Controls
If (TypeOf ctl Is PictureBox) Then
Dim picBox As PictureBox = DirectCast(ctl, PictureBox)
picBox.Image.Dispose()
End If
Next ctl
Dim s As String
For Each s In System.IO.Directory.GetFiles("C:\Program Files (x86)\myMovie Manager v3.01\Posters")
Try
System.IO.File.Delete(s)
Catch ex As Exception
End Try
Next s
'download HD Movie poster
Try
updateHDPoster(Form1.directorylist(i), "\MetaData\movieData.xml", i)
Catch ex As Exception
End Try
Try
'Copy image
System.IO.File.Copy(file, Form1.directorylist(i) + "\folder.jpg", True)
Me.Close()
Catch ex As Exception
End Try
End Sub
Thanks for having a look
kevin

New Topic/Question
Reply



MultiQuote






|