温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

VB ConsoleProgressBar有什么作用

发布时间:2021-12-04 15:23:47 来源:亿速云 阅读:133 作者:iii 栏目:编程语言

本篇内容介绍了“VB ConsoleProgressBar有什么作用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

CopyFiles负责取得源目录下的一个文件列表,然后把它们复制到目的目录下。另外,它还创建了一个ConsoleProgressBar对象来管理进度条:

Private Sub CopyFiles(ByVal srcDir As String, ByVal destDir As String)  Const BufferSourceTopLine As Integer = 8 Const BufferDestinationTopLine As Integer = 7 Dim rowIndex As Integer = 7 Dim originalForegroundColor As ConsoleConsoleColor = Console.ForegroundColor  Console.CursorVisible = False Console.Clear()  Dim numberOfFiles As Integer  numberOfFiles = My.Computer.FileSystem.GetFiles(srcDir).Count  Dim PB As New ConsoleProgressBar(numberOfFiles)  DisplayHeader(srcDir, destDir)  Dim fileCounter As Integer = 1 For Each f As String In My.Computer.FileSystem.GetFiles(srcDir)  Dim fi As New System.IO.FileInfo(f)  Console.ForegroundColor = ConsoleColor.Green  Console.SetCursorPosition(0, rowIndex)  Console.Write(fi.Name)  If rowIndex < Console.WindowHeight - 1 Then  rowIndex += 1  Else  Console.MoveBufferArea(0,BufferSourceTopLine, _  Console.WindowWidth, _  Console.WindowHeight - _  BufferSourceTopLine, _  0, _  BufferDestinationTopLine)  End If  My.Computer.FileSystem.CopyFile(fi.FullName, destDir &"\" & fi.Name)  pb.Update( fileCounter)  fileCounter += 1  Next  Console.ForegroundColor = originalForegroundColor Console.SetCursorPosition(0, Console.WindowHeight - 1)  Console.CursorVisible = True End Sub

首先,该代码保存当前的ForegroundColor。然后,它使用另外一种新特征把CursorVisible属性设置为False。在清除控制台窗口后,它检索在源目录下的文件个数并且使用这个数字作为VB ConsoleProgressBar构造器的***值。稍后,我还要讨论有关于 ConsoleProgressBar的细节信息。

我调用DisplayHeader子程序来把一些有关复制操作的信息打印到控制台窗口。由于其功能非常类似于DisplayUsage子程序,所以我在此省略对其细节的讨论。

我使用了一个“For...Each”循环来遍历在源目录下的所有文件,并使用了一个rowIndex变量来跟踪要把文件名打印到控制台的哪一行。随着循环的不断执行,rowIndex每次增加1,直到到达控制台窗口的底部为止。一旦到达控制台窗口的底部,我利用另外一个新控制台应用程序特征— MoveBufferArea方法(下一节讨论)。

在更新显示和复制文件后,我通过调用VB ConsoleProgressBar类的Update方法来更新进度条。

一旦循环结束并且文件复制结束,我再把ForegroundColor设置回其原来的颜色,并且把光标位置设置到控制台窗口的最下面一行,并且使之再次可见。

“VB ConsoleProgressBar有什么作用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vb
AI