【发布时间】:2015-05-12 21:01:28
【问题描述】:
我有这个与文件路径一起工作的代码,但我试图让它在完成搜索后将文本更改为“搜索完成”。这是我尝试过的,我在没有 100 左右的引号的情况下尝试了它,但它仍然无法正常工作,任何指针。
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim argument = DirectCast(e.Argument, Tuple(Of String, String))
Dim target = argument.Item1
Dim folderPath = argument.Item2
Dim filePaths = IO.Directory.GetFiles(folderPath, "*.txt")
'Report the total file count.
Me.BackgroundWorker1.ReportProgress(filePaths.Length)
For Each filePath In filePaths
'Report progress.
Me.BackgroundWorker1.ReportProgress(CInt(False), filePath)
If IO.File.ReadAllText(filePath).Contains(target) Then
'Report a successful search.
Me.BackgroundWorker1.ReportProgress(CInt(True), filePath)
End If
Next
End Sub
Private Sub backgroundworker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Dim filePath = DirectCast(e.UserState, String)
If filePath Is Nothing Then
'This is the total file count.
Me.dataprogbar.Maximum = e.ProgressPercentage
ElseIf CBool(e.ProgressPercentage) Then
'This is a successful search.
Me.ListBox1.Items.Add(filePath)
Else
'This is a simple progress update.
Me.dataprogbar.PerformStep()
Me.Label1.Text = filePath
If dataprogbar.Value = "100" Then
Label1.Text = "Search Completed"
End If
End If
End Sub
【问题讨论】:
-
那么当您“完成搜索”时,
dataprogbar.Value的值是多少?我猜它不是 100。 -
@TheBlueDog 最大值设置为100
-
@TheBlueDog 我添加了整个代码,所以最大值 = e.progresspercentage
-
我再问一次,当你“搜索完毕”时,
dataprogbar.Value的值是多少?此时,您将最大值设置为什么都无关紧要。 -
"
the value should be 100 when done searching" 它应该是,或者它是 = 100 ?
标签: vb.net label progress-bar