Solved

Need Help With VB.Net program I am writing

Posted on 2010-09-07
7
431 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now