Solved

Need Help With VB.Net program I am writing

Posted on 2010-09-07
7
435 Views
Last Modified: 2012-05-10
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
Comment
Question by:T-Cornett
7 Comments
 
LVL 8

Assisted Solution

by:Mikkk
Mikkk earned 166 total points
ID: 33622040
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
 
LVL 17

Assisted Solution

by:Zhaolai
Zhaolai earned 166 total points
ID: 33622147
Also make sure to pass the full path.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 168 total points
ID: 33622334
...or your passing the same path to the DisplayThumbs() method every time.
0
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!

 

Author Comment

by:T-Cornett
ID: 33622367
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33622468
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
 

Author Comment

by:T-Cornett
ID: 33622554
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
 

Author Closing Comment

by:T-Cornett
ID: 33622616
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question