如何在复制文件时设置进度条 [英] how to set progress bar during copying file
本文介绍了如何在复制文件时设置进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI
请问,如何在将文件从一个文件夹复制到另一个文件夹时,如何在表格上设置进度条。
解决方案
Dim sr 作为 新 IO.FileStream( [copyfrom],IO.FileMode.Open)
Dim sw 作为 新 IO.FileStream( [copyto],IO.FileMode.Create)
Dim len 作为 长 = sr.Length - 1
Dim 缓冲区( 1024 ) As 字节
Dim bytesread 作为 整数
sr.Position< len
bytesread =(sr.Read(缓冲区, 0 , 1024 ))
sw.Write(buffer, 0 ,bytesread)
ProgressBar1.Value = CInt (sr) .Position / len * 100 )
Application.DoEvents()
结束 < span class =code-keyword> while
sw.Flush()
sw.Close()
sr.Close()
HI Please, how can i set my progress the progressbar on my form during copying file from one folder to another folder.
解决方案
Dim sr As New IO.FileStream("[copyfrom]", IO.FileMode.Open) Dim sw As New IO.FileStream("[copyto]", IO.FileMode.Create) Dim len As Long = sr.Length - 1 Dim buffer(1024) As Byte Dim bytesread As Integer While sr.Position < len bytesread = (sr.Read(buffer, 0, 1024)) sw.Write(buffer, 0, bytesread) ProgressBar1.Value = CInt(sr.Position / len * 100) Application.DoEvents() End While sw.Flush() sw.Close() sr.Close()
这篇关于如何在复制文件时设置进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文