Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

Need Help With VB.Net program I am writing

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
        FlowLayoutPanel1.Controls.Clear()
        FlowLayoutPanel1.Refresh()

        ' 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)
            Try
                oPicInf = New FileInfo(thpic)

                If sMyExt.Contains(LCase(oPicInf.Extension)) Then

                    ' CREATE NEW THUMB CONTROL
                    pBox2 = New asThumb

                    ' UPDATE PROGRESS
                    ProgressBar1.Increment(1)

                    ' OPEN IMAGE AND CREATE THUMBNAIL
                    oImg = Image.FromFile(oPicInf.FullName)
                    pBox2.CreateThumbnail(oPicInf.FullName)

                    ' ADD THUMB CONTROL TO FLOW LAYOUT PANEL CONTROL
                    Me.FlowLayoutPanel1.Controls.Add(pBox2)

                    ' UPDATE THE COUNT
                    iPicNo += 1

                    ' ADD THE EVENT HANDLER IN ORDER TO DETERMINE WHICH THUMB WAS CLICKED
                    AddHandler pBox2.ThumbClicked, AddressOf ThumbClicked

                End If

            Catch ex As Exception
                MsgBox(ex.Message, 48)

            End Try
        Next

        ' RESET THE PROGRESS
        ProgressBar1.Value = 0
        ProgressBar1.Visible = False

        ' UPDATE THE STATUS BAR
        sbInfo.Text = "Scanned " + CStr(iPicNo) + " Image(s)."

    End Sub

Open in new window

screenshot-01.jpg
0
T-Cornett
Asked:
T-Cornett
3 Solutions
 
MikkkCommented:
It seems that procedure "DisplayThumbs" is not called when you change the selected tree node.

If you debug the second time, does the code executes the procedure? maybe you have to change the event type that launch the procedure.

Witch event dou you catch from the treeview?
0
 
ZhaolaiCommented:
Also make sure to pass the full path.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
...or your passing the same path to the DisplayThumbs() method every time.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
T-CornettAuthor Commented:
Mikkk & Zhaolai

It is called from the AfterSelect event of the treeview control I am using to display the drives and folders in.

Yes it passes the full path including the trailing \
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You could add a MessageBox at the beginning to see what path is actually being received:

    Private Sub DisplayThumbs(ByVal sPath As String)
        MessageBox.Show("Building Thumbs for: " & sPath)
0
 
T-CornettAuthor Commented:
Idle_Mind,

If you look at the screen shot you can see the path in the status bar is different.

The status bar text is updated in the same event that calls DisplayThumbs()

They both use the same directory path information. The status bar is updated first then DisplayThumbs() is called. As you can see the status is updated but the new thumbs are not created and the old ones are not removed.

I added a menu item and called DisplayThumbs() from there. The menu item uses the BrowseForFolder dialog to get the directory path. it works this way but not when using the treeview.


Private Sub mSelectFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mSelectFolder.Click

        ' SELECT THE DIRECTORY TO DISPLAY
        With FolderBrowserDialog1
            .SelectedPath = My.Settings.LastDir
        End With

        If FolderBrowserDialog1.ShowDialog <> 1 Then Exit Sub

        ' SAVE LAST DIRECTORY VIEWED
        My.Settings.LastDir = FolderBrowserDialog1.SelectedPath

        DisplayThumbs(FolderBrowserDialog1.SelectedPath)

    End Sub

Open in new window

0
 
T-CornettAuthor Commented:
OK I feel stupid now. If you look at the screenshot I make sure the trailing "\" is at the end of the path.

If I remove that last backslash before passing the path to the DisplathThumbs routine it works. Not sure why that is.

Since you were kind enough to help I am dividing the points between you..
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now