进度条太快

时间:2018-02-13 20:09:13

标签: .net vb.net winforms

进度条首先跟踪文件的复制,然后更新其内容。出于某种原因,进度条在文件全部更新之前第二次达到100%。

Private Sub cmdGenerate_Click(sender As Object, e As EventArgs) Handles cmdGenerate.Click
    Dim CatalogFiles As String() = IO.Directory.GetFiles(dirCatalogues & "\" & cboCatalog.Text, "*"),
        NewFile As String,
        cnt As Integer = 0
    prg.Visible = True
    lblProgress.Visible = True
    Dim dwgs As String() = IO.Directory.GetFiles(dirNewProject, "*.dwg")
    prg.Minimum = 0
    prg.Maximum = dwgs.Length
    prg.Value = 0
    lblProgress.Text = "Updating drawings:"
    For Each dwg In dwgs
        CAD.FindReplace(dwg, strNomenclatureFind, strNomenclatureReplace)
        CAD.FindReplace(dwg, strProjectNameFind, strProjectNameReplace)
        cnt = cnt + 1
        prg.Increment(cnt)
    Next
    MsgBox("Done.")
    ResetForm()
End Sub

1 个答案:

答案 0 :(得分:2)

您正在使用prg.Increment(cnt),请将其替换为prog.Increment(1),因为增量为:

  

增加进度条当前位置的数量。

或者将其替换为prg.Value(cnt),因为值为:

  

获取或设置进度条的当前位置。

参考文献: