我正在尝试让进度条显示当前的进度,但由于某种原因,进度条刚刚显示在那里并且没有发生任何事情。我正在使用以下代码
Private Sub BuildApp_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BuildApp.ProgressChanged
Me.ProgressBar1.Value = e.ProgressPercentage
End Sub
我检查后台工作者的属性是否设置为报告状态,并将其设置为“是”。另外,我检查了进度条的样式,它设置为Blocks。有什么帮助吗?
答案 0 :(得分:4)
这是一个简单的例子......
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