詳細(xì)分析VB Update方法
本文向大家介紹VB Update方法,可能好多人還不了解VB Update方法,沒(méi)有關(guān)系,看完本文你肯定有不少收獲,希望本文能教會(huì)你更多東西。在VB Update方法被調(diào)用前,在ConsoleProgressBar對(duì)象中什么也沒(méi)有發(fā)生:
- Public Sub Update(ByVal CurrentValue As Long)
- m_currentValue = CurrentValue
- m_currentBarLength = CInt((m_currentValue / m_maximumValue) * m_length)
- Refresh()
- End Sub
這個(gè)VB Update方法使用一個(gè)值作參數(shù)(在此是指當(dāng)前剛剛復(fù)制的文件數(shù))。我設(shè)置成員m_currentValue,然后計(jì)算m_currentBarLength。計(jì)算的結(jié)果為進(jìn)度條當(dāng)前應(yīng)該覆蓋的列數(shù)。
最后,我調(diào)用Refresh方法,它又調(diào)用UpdatePercentComplete、UpdateProgressBar和UpdateMessageBar方法。
因?yàn)樗羞@三個(gè)方法功能相類似,所以我將集中討論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
首先,該代碼保存當(dāng)前的前景和背景顏色。然后,它把ForegroundColor屬性設(shè)置為黑色,把BackgroundColor屬性設(shè)置為綠色。在把光標(biāo)放置到進(jìn)度條的左邊緣后,它打印一串長(zhǎng)度為m_currentBarLength的“O”。
其它問(wèn)題
這個(gè)DirCopy應(yīng)用程序,雖然有些用處,但是還遠(yuǎn)非成品。為了使其更為強(qiáng)壯,還需要增加大量的錯(cuò)誤處理方式。你還可以改進(jìn)ConsoleProgressBar類以實(shí)現(xiàn)更靈活的控制。下列是一些可能的改進(jìn):
◆允許控制進(jìn)度條的位置和長(zhǎng)度
◆允許百分比完成區(qū)域放到你選擇的任何位置
◆允許定制進(jìn)度條中的消息
◆添加一個(gè)選項(xiàng)以選擇水平的或垂直的進(jìn)度條
【編輯推薦】