I am learning Visual Basic.net and need some help. I am writing an image viewer program that displays thumbnails for the selected directory. I created my own user control for the thumbnail so I could display more than just the filename of the image.
I use a FlowLayoutPanel control to display the thumbnails in.
When you click on a directory it calls a routine that creates the thumbnails for the passed DirPath.
It works fine for the first directory selected but does not work on any other. It shows the progress bar then stops. It does not clear the old thumbs from the FlowLayoutPanel or create the new ones.
There is no error and the program does not freeze. I can still click the thumbs that were created and the event that displays them full screen still fires.
I have included the routine and a before and after screen shot of the application window.
The strange thing is if I don't use the treeview to get the path but call a BrowseForFolder dialog from within the routine and call it from a button it works every time the routine is called.
Any help would be appreciated.
Private Sub DisplayThumbs(ByVal sPath As String)
Dim iPicNo As Integer
Dim oImg As Image
sbInfo.Text = " "
' CLEAR THE OLD THUMBS IF ANY
' SETUP PROGRESS
ProgressBar1.Maximum = Directory.GetFiles(sPath).Length
ProgressBar1.Minimum = 0
ProgressBar1.Visible = True
' CREATE THE THUMBS
For Each thpic As String In Directory.GetFiles(sPath)
oPicInf = New FileInfo(thpic)
If sMyExt.Contains(LCase(oPicInf.Extension)) Then
' CREATE NEW THUMB CONTROL
pBox2 = New asThumb
' UPDATE PROGRESS
' OPEN IMAGE AND CREATE THUMBNAIL
oImg = Image.FromFile(oPicInf.FullName)
' ADD THUMB CONTROL TO FLOW LAYOUT PANEL CONTROL
' UPDATE THE COUNT
iPicNo += 1
' ADD THE EVENT HANDLER IN ORDER TO DETERMINE WHICH THUMB WAS CLICKED
AddHandler pBox2.ThumbClicked, AddressOf ThumbClicked
Catch ex As Exception
' RESET THE PROGRESS
ProgressBar1.Value = 0
ProgressBar1.Visible = False
' UPDATE THE STATUS BAR
sbInfo.Text = "Scanned " + CStr(iPicNo) + " Image(s)."