新聞中心
在向大家詳細(xì)介紹VB ConsoleProgressBar之前,首先讓大家了解下CopyFiles,然后全面介紹VB ConsoleProgressBar。CopyFiles負(fù)責(zé)取得源目錄下的一個(gè)文件列表,然后把它們復(fù)制到目的目錄下。另外,它還創(chuàng)建了一個(gè)ConsoleProgressBar對(duì)象來(lái)管理進(jìn)度條:

創(chuàng)新互聯(lián)是專(zhuān)業(yè)的洛寧網(wǎng)站建設(shè)公司,洛寧接單;提供網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行洛寧網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
- 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
首先,該代碼保存當(dāng)前的ForegroundColor。然后,它使用另外一種新特征把CursorVisible屬性設(shè)置為False。在清除控制臺(tái)窗口后,它檢索在源目錄下的文件個(gè)數(shù)并且使用這個(gè)數(shù)字作為VB ConsoleProgressBar構(gòu)造器的***值。稍后,我還要討論有關(guān)于 ConsoleProgressBar的細(xì)節(jié)信息。
我調(diào)用DisplayHeader子程序來(lái)把一些有關(guān)復(fù)制操作的信息打印到控制臺(tái)窗口。由于其功能非常類(lèi)似于DisplayUsage子程序,所以我在此省略對(duì)其細(xì)節(jié)的討論。
我使用了一個(gè)“For...Each”循環(huán)來(lái)遍歷在源目錄下的所有文件,并使用了一個(gè)rowIndex變量來(lái)跟蹤要把文件名打印到控制臺(tái)的哪一行。隨著循環(huán)的不斷執(zhí)行,rowIndex每次增加1,直到到達(dá)控制臺(tái)窗口的底部為止。一旦到達(dá)控制臺(tái)窗口的底部,我利用另外一個(gè)新控制臺(tái)應(yīng)用程序特征— MoveBufferArea方法(下一節(jié)討論)。
在更新顯示和復(fù)制文件后,我通過(guò)調(diào)用VB ConsoleProgressBar類(lèi)的Update方法來(lái)更新進(jìn)度條。
一旦循環(huán)結(jié)束并且文件復(fù)制結(jié)束,我再把ForegroundColor設(shè)置回其原來(lái)的顏色,并且把光標(biāo)位置設(shè)置到控制臺(tái)窗口的最下面一行,并且使之再次可見(jiàn)。
新聞標(biāo)題:VBConsoleProgressBar簡(jiǎn)單介紹
文章分享:http://m.fisionsoft.com.cn/article/ccdcgcp.html


咨詢(xún)
建站咨詢(xún)
