在update方法被调用前,在consoleprogressbar对象中什么也没有发生:
public sub update(byval currentvalue as long)
m_currentvalue = currentvalue
m_currentbarlength = cint((m_currentvalue / m_maximumvalue) * m_length)
refresh()
end sub
这个update方法使用一个值作参数(在此是指当前刚刚复制的文件数)。我设置成员m_currentvalue,然后计算m_currentbarlength。计算的结果为进度条当前应该覆盖的列数。
最后,我调用refresh方法,它又调用updatepercentcomplete、updateprogressbar和updatemessagebar方法。
因为所有这三个方法功能相类似,所以我将集中讨论updateprogressbar方法:
private sub updateprogressbar()
dim originalforegroundcolor as consolecolor = console.foregroundcolor
dim originalbackgroundcolor as consolecolor = 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
你一定很想看到应用程序运行情况(参考图2和3),并想检查一下运行结果(参考图4)。我建立了一个目录,并使用一串哑文件来测试复制。我建议,在你使用dircopy复制任何关键文件前,你也这样试验一下。
图2:开始dircopy
图3:dircopy运行中
图4:dircopy运行完成
九、 其它问题
这个dircopy应用程序,虽然有些用处,但是还远非成品。为了使其更为强壮,还需要增加大量的错误处理方式。你还可以改进consoleprogressbar类以实现更灵活的控制。下列是一些可能的改进:
· 允许控制进度条的位置和长度
· 允许百分比完成区域放到你选择的任何位置
· 允许定制进度条中的消息
· 添加一个选项以选择水平的或垂直的进度条
十、 小结
我希望,本文有助于你了解vb 2005所提供的部分新的控制台应用程序特征,尽管这些特征仅是其中的一部分。另外,我还鼓励你再分析一下其它一些控制台应用程序特征,并与本文介绍相结合以发现你更喜欢的特征。 做人要厚道,请注明转自酷网动力(www.aspcool.com)。
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!


