【发布时间】:2016-09-30 08:04:25
【问题描述】:
和标题一样,我想要一个进度条,它在复制时显示过程。
到目前为止我的代码:
导入 System.IO 导入脚本
公开课表1 暗淡的源,目的地为字符串 Dim fso As FileSystemObject = New FileSystemObject 将 SourceSize 调暗为 Double
Private Sub ResetThings()
ProgressBar1.Value = 0
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xFilesCount = Directory.GetFiles(Source).Length
Dim xFilesTransferred As Integer = 0
For Each xFiles In Directory.GetFiles(Source)
My.Computer.FileSystem.CopyDirectory(Source, Destination, True)
xFilesTransferred += 1
ProgressBar1.Value = xFilesTransferred * 100 / xFilesCount
ProgressBar1.Update()
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
FolderBrowserDialog1.ShowDialog()
Source = FolderBrowserDialog1.SelectedPath
first.Text = "Original: " & Source
ResetThings()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
FolderBrowserDialog1.ShowDialog()
Destination = FolderBrowserDialog1.SelectedPath
Dim Temp = Source
Do
Temp = Temp.Substring(1)
Loop Until Temp.Contains("\") = False
Destination = Destination
Second.Text = "Ziel: " & Destination
End Sub
【问题讨论】:
-
你有什么问题?
-
进度条没有显示任何内容。但是文件正在复制...
-
我建议通过查看它,您需要设置
ProgressBar1.Maximum。然后你可以使用这一行ProgressBar1.Increment(1)让它在每个文件之后上升一个。并且因为您设置了最大值,所以一旦完成所有文件,进度条应该是完整的 -
好的,谢谢.. 但是如何在我的代码中使用 ProgressBar1.Maximum 和 ProgressBar1.Increment(1)?第一次使用进度条:)
-
问题是你没有复制文件,而是整个目录——这是一个命令,不会刷新任何东西。
标签: vb.net