I am trying to add Images using open file dialog and folder browse dialog and populating the image list to listbox.While adding these Images I need to show the progress bar for every image it loads.
I am trying to get that but when the value of the progress bar say something around 25 0r 40 it is stopping at that point but I need to show the progress bar until it completes the 100% and then populates the Image list.
How do I do that?
Here is my code:
Private Sub AddImages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddImages.Click
If Not Directory.Exists(Application.StartupPath + "\Backup\") = True Then
Directory.CreateDirectory(Application.StartupPath + "\Backup\")
End If
OpenFileDialog1.FileName = "Select a Image"
OpenFileDialog1.Multiselect = True
OpenFileDialog1.InitialDirectory = "C:\Users\Public\Pictures\Sample Pictures"
OpenFileDialog1.Filter = "All Type Of Image Files|*.*|Joint Photographic Experts Group [JPEG]|*.jpg|Bitmap [BMP|*.bmp|Tagged Image File Format [TIFF]|*.tiff|Portable Network Graphics [PNG]|*.png"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
ProgressBar2.Show()
ProgressBar2.Step = 10
Dim str As String
For Each str In OpenFileDialog1.FileNames
Load.Text = "Loading..."
Dim fso As New FileSystemObject
Dim MyName As String
Dim MyExtension As String
MyName = fso.GetFileName(CStr(str))
MyExtension = fso.GetExtensionName(MyName)
System.IO.File.Copy(str, Application.StartupPath + "\Backup\" + MyName & "." & MyExtension, True)
CheckedListBox1.Items.Add(str, CheckState.Checked)
Thumbcontrol1.AddThumbnail(str)
Thumbcontrol1.BackgroundImage = Nothing
CheckedListBox1.SelectedIndex = 0
ProgressBar2.PerformStep()
Next
SaveProject.Enabled = True
Delete.Enabled = True
Edit.Enabled = True
ClearAll.Enabled = True
CheckAll.Enabled = True
UncheckAll.Enabled = True
Timer1.Stop()
Load.Text = "Loading Completed"
Else
End If
ProgressBar2.Visible = False
Load.Text = Nothing
End Sub
Remove
ProgressBar2.Step = 10line and do this:It does not address the problem of your not using threading, as other answers are correct to point out.