Solved

Need Help With VB.Net program I am writing

Posted on 2010-09-07
7
436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

Accepted Solution

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copying from a network share 3 38
Read oracle BLOB in vb.net 2 24
.NET Redemption/Outlook Examples 3 35
Datatable / Dates ? 4 33
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…

752 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