自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

VB ConsoleProgressBar簡單介紹

開發(fā) 后端
這里介紹VB ConsoleProgressBar,包括介紹調(diào)用DisplayHeader子程序來把一些有關(guān)復(fù)制操作的信息打印到控制臺窗口。

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

  1. Private Sub CopyFiles(ByVal srcDir As String, ByVal destDir As String)  
  2. Const BufferSourceTopLine As Integer = 8 
  3. Const BufferDestinationTopLine As Integer = 7 
  4. Dim rowIndex As Integer = 7 
  5. Dim originalForegroundColor As ConsoleConsoleColor = Console.ForegroundColor  
  6. Console.CursorVisible = False 
  7. Console.Clear()  
  8. Dim numberOfFiles As Integer  
  9. numberOfFiles = My.Computer.FileSystem.GetFiles(srcDir).Count  
  10. Dim PB As New ConsoleProgressBar(numberOfFiles)  
  11. DisplayHeader(srcDir, destDir)  
  12. Dim fileCounter As Integer = 1 
  13. For Each f As String In My.Computer.FileSystem.GetFiles(srcDir)  
  14. Dim fi As New System.IO.FileInfo(f)  
  15. Console.ForegroundColor = ConsoleColor.Green  
  16. Console.SetCursorPosition(0, rowIndex)  
  17. Console.Write(fi.Name)  
  18. If rowIndex < Console.WindowHeight - 1 Then  
  19. rowIndex += 1  
  20. Else  
  21. Console.MoveBufferArea(0,BufferSourceTopLine, _  
  22. Console.WindowWidth, _  
  23. Console.WindowHeight - _  
  24. BufferSourceTopLine, _  
  25. 0, _  
  26. BufferDestinationTopLine)  
  27. End If  
  28. My.Computer.FileSystem.CopyFile(fi.FullName, destDir &"\" & fi.Name)  
  29. pb.Update( fileCounter)  
  30. fileCounter += 1  
  31. Next  
  32. Console.ForegroundColor = originalForegroundColor 
  33. Console.SetCursorPosition(0, Console.WindowHeight - 1)  
  34. Console.CursorVisible = True 
  35. End Sub  

首先,該代碼保存當前的ForegroundColor。然后,它使用另外一種新特征把CursorVisible屬性設(shè)置為False。在清除控制臺窗口后,它檢索在源目錄下的文件個數(shù)并且使用這個數(shù)字作為VB ConsoleProgressBar構(gòu)造器的***值。稍后,我還要討論有關(guān)于 ConsoleProgressBar的細節(jié)信息。

我調(diào)用DisplayHeader子程序來把一些有關(guān)復(fù)制操作的信息打印到控制臺窗口。由于其功能非常類似于DisplayUsage子程序,所以我在此省略對其細節(jié)的討論。

我使用了一個“For...Each”循環(huán)來遍歷在源目錄下的所有文件,并使用了一個rowIndex變量來跟蹤要把文件名打印到控制臺的哪一行。隨著循環(huán)的不斷執(zhí)行,rowIndex每次增加1,直到到達控制臺窗口的底部為止。一旦到達控制臺窗口的底部,我利用另外一個新控制臺應(yīng)用程序特征— MoveBufferArea方法(下一節(jié)討論)。

在更新顯示和復(fù)制文件后,我通過調(diào)用VB ConsoleProgressBar類的Update方法來更新進度條。

一旦循環(huán)結(jié)束并且文件復(fù)制結(jié)束,我再把ForegroundColor設(shè)置回其原來的顏色,并且把光標位置設(shè)置到控制臺窗口的最下面一行,并且使之再次可見。

【編輯推薦】

  1. VB 2005中開發(fā)新一代控制臺應(yīng)用程序
  2. 簡單講解VB開發(fā)分布式
  3. 淺析VB Script開發(fā)自動化測試
  4. 淺談VB開發(fā)系統(tǒng)知識
  5. VB.NET應(yīng)用程序中多線程的應(yīng)用實例
責任編輯:佚名 來源: 博客園
相關(guān)推薦

2009-10-10 12:50:05

VB ConsoleP

2009-10-12 13:19:14

VB.NET線程同步

2009-11-10 10:28:20

VB.NET誕生

2009-10-09 16:29:45

VB生成安裝盤

2009-08-18 16:57:24

VB.NET和C#

2010-01-07 16:40:13

VB.NET一維數(shù)組

2009-11-02 10:36:16

VB.NET Sub

2010-01-11 18:32:42

VB.NET序列化

2009-10-23 17:22:48

VB.NET編程

2009-11-03 14:13:23

VB.NET C#

2009-10-28 09:55:29

VB.NET MyCl

2009-10-16 13:26:53

VB.NET Exce

2009-10-15 17:44:40

VB6.0 datat

2009-06-17 17:59:01

介紹Spring

2011-02-24 14:40:47

Proftpd

2011-02-23 13:28:12

2011-01-21 16:49:15

Zimbra

2011-01-21 10:40:52

Sendmail

2011-04-01 09:39:17

zabbix

2011-03-04 13:19:09

VSFTP介紹
點贊
收藏

51CTO技術(shù)棧公眾號