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
Solved

Need Help With VB.Net program I am writing

Posted on 2010-09-07
7
434 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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