詳細分析VB Update方法
本文向大家介紹VB Update方法,可能好多人還不了解VB Update方法,沒有關系,看完本文你肯定有不少收獲,希望本文能教會你更多東西。在VB Update方法被調用前,在ConsoleProgressBar對象中什么也沒有發生:
- Public Sub Update(ByVal CurrentValue As Long)
- m_currentValue = CurrentValue
- m_currentBarLength = CInt((m_currentValue / m_maximumValue) * m_length)
- Refresh()
- End Sub
這個VB Update方法使用一個值作參數(在此是指當前剛剛復制的文件數)。我設置成員m_currentValue,然后計算m_currentBarLength。計算的結果為進度條當前應該覆蓋的列數。
最后,我調用Refresh方法,它又調用UpdatePercentComplete、UpdateProgressBar和UpdateMessageBar方法。
因為所有這三個方法功能相類似,所以我將集中討論UpdateProgressBar方法:
- Private Sub UpdateProgressBar()
- Dim originalForegroundColor As ConsoleConsoleColor = Console.ForegroundColor
- Dim originalBackgroundColor As ConsoleConsoleColor = Console .BackgroundColor
- Console.ForegroundColor = ConsoleColor.Black
- Console.BackgroundColor = ConsoleColor.Green
- Console.SetCursorPosition(m_left + 1 m_progressBarRow)
- Dim progress As New String("O", m_currentBarLength)
- Console.Write(progress)
- Console.ForegroundColor =originalForegroundColor
- Console.BackgroundColor = originalBackgroundColor
- End Sub
首先,該代碼保存當前的前景和背景顏色。然后,它把ForegroundColor屬性設置為黑色,把BackgroundColor屬性設置為綠色。在把光標放置到進度條的左邊緣后,它打印一串長度為m_currentBarLength的“O”。
其它問題
這個DirCopy應用程序,雖然有些用處,但是還遠非成品。為了使其更為強壯,還需要增加大量的錯誤處理方式。你還可以改進ConsoleProgressBar類以實現更靈活的控制。下列是一些可能的改進:
◆允許控制進度條的位置和長度
◆允許百分比完成區域放到你選擇的任何位置
◆允許定制進度條中的消息
◆添加一個選項以選擇水平的或垂直的進度條
【編輯推薦】