0

我正在尝试让进度条显示当前进度,但由于某种原因,进度条只是显示在那里并且没有发生任何事情。我正在使用以下代码

Private Sub BuildApp_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BuildApp.ProgressChanged
        Me.ProgressBar1.Value = e.ProgressPercentage
End Sub

我检查了后台工作人员的属性是否设置为报告状态并将其设置为“是”。另外,我检查了进度条的样式,它设置为块。有什么帮助吗?

4

1 回答 1

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
于 2013-07-07T23:40:29.570 回答