frmMain 有一个启动后台工作程序的按钮
Private Sub btnProcessITN_Click(sender As Object, e As EventArgs) Handles btnProcessITN.Click
Me.frmMainProgressBar.Visible = True
Me.btnProcessITN.Text = "working..." & Me.frmMainProgressBar.Value & "%"
Me.btnProcessITN.Enabled = False
backgroundWorker2.WorkerReportsProgress = True
BackgroundWorker2.RunWorkerAsync()
End Sub
Private Sub backgroundWorker2_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
ProcessITN()
End Sub
ProcessITN 存在于 modITN 中。这运行,做它的事,然后问题
Public Sub ProcessITN()
...doing work here....
frmMain.updateProgress(current, Max)
End Sub
然后回到主窗体我有一个函数试图更新后台工作人员的进度,并更新窗体上的进度条
Public Function updateProgress(current As Integer, Max As Integer) As Boolean
BackgroundWorker2.ReportProgress((current / Max) * 100)
Return True
End Function
Private Sub backgroundWorker2_ProgressChanged( _
ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) _ Handles BackgroundWorker2.ProgressChanged
Me.frmMainProgressBar.Value = e.ProgressPercentage
Me.btnProcessITN.Text = "working..." & Me.frmMainProgressBar.Value & "%"
'Me.txtProgress.Text = Me.txtProgress.Text & vbNewLine & strMessage
Me.txtProgress.AppendText(vbNewLine & strMessage)
End Sub
现在,问题是,虽然代码正在运行,并且值从 modITN 正确传递到 frmMain,但表单本身并没有刷新。进度条没有改变。txtProgress 不会改变。
请注意,当 modITN 中的内容位于 frmMain 中时,此代码运行良好。我移动它以尝试整理我的代码。