在vb.net中使用进度条

时间:2015-05-23 15:43:18

标签: vb.net

我在下面有示例代码,用于进度条。我需要显示每个循环项目的进度(百分比和条形)

For i = 0 To 200000
            ListBox1.Items.Add(i)
        Next

我已经尝试了所有东西(后台工作人员等),但无法弄明白。

我请求有人给我写完整的代码(背景工程,交叉线程等等)并帮助我让它运行。

提前多多感谢。

1 个答案:

答案 0 :(得分:0)

你在这里,但不要忘记这不是一个好主意:

Dim max As Integer = 200000
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Me.ProgressBar1.Maximum = max
    BackgroundWorker1.WorkerReportsProgress = True
End Sub

Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    For i = 1 To max
        BackgroundWorker1.ReportProgress(i)
    Next
End Sub

Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
    Dim i = e.ProgressPercentage
    ProgressBar1.Value = i
    ListBox1.Items.Add(i)
    'ListBox1.SelectedIndex = i - 1
End Sub