Reputation: 93
I'm trying to make the progress bar show the current progress but for some reason the progress bar is just shown there and nothing is happening. I'm using the following code
Private Sub BuildApp_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BuildApp.ProgressChanged
Me.ProgressBar1.Value = e.ProgressPercentage
End Sub
I checked if the background worker's property is set to report status and it is set to "Yes". Also, I checked the progress bar's style, it's set to Blocks. Any help?
Upvotes: 0
Views: 430
Reputation: 39152
Here's a simple example...
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
BuildApp.RunWorkerAsync()
End Sub
Private Sub BuildApp_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BuildApp.DoWork
Dim someTotal As Integer = 12
For x As Integer = 1 To someTotal
System.Threading.Thread.Sleep(1000) ' simulated work
BuildApp.ReportProgress(x / someTotal * 100) ' pass the current percentage value
Next
End Sub
Private Sub BuildApp_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BuildApp.ProgressChanged
Me.ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BuildApp_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BuildApp.RunWorkerCompleted
MessageBox.Show("Done!")
Button1.Enabled = True
End Sub
End Class
Upvotes: 4