详细分析VB Update方法

开发 后端
这里介绍VB Update方法使用一个值作参数,我设置成员m_currentValue,然后计算m_currentBarLength。计算的结果为进度条当前应该覆盖的列数。

本文向大家介绍VB Update方法,可能好多人还不了解VB Update方法,没有关系,看完本文你肯定有不少收获,希望本文能教会你更多东西。在VB Update方法被调用前,在ConsoleProgressBar对象中什么也没有发生:

  1. Public Sub Update(ByVal CurrentValue As Long)  
  2. m_currentValue = CurrentValue 
  3. m_currentBarLength = CInt((m_currentValue / m_maximumValue) * m_length)  
  4. Refresh()  
  5. End Sub  

这个VB Update方法使用一个值作参数(在此是指当前刚刚复制的文件数)。我设置成员m_currentValue,然后计算m_currentBarLength。计算的结果为进度条当前应该覆盖的列数。

最后,我调用Refresh方法,它又调用UpdatePercentComplete、UpdateProgressBar和UpdateMessageBar方法。

因为所有这三个方法功能相类似,所以我将集中讨论UpdateProgressBar方法:

  1. Private Sub UpdateProgressBar()  
  2. Dim originalForegroundColor As ConsoleConsoleColor = Console.ForegroundColor  
  3. Dim originalBackgroundColor As ConsoleConsoleColor = Console .BackgroundColor  
  4. Console.ForegroundColor = ConsoleColor.Black  
  5. Console.BackgroundColor = ConsoleColor.Green  
  6. Console.SetCursorPosition(m_left + 1 m_progressBarRow)  
  7. Dim progress As New String("O", m_currentBarLength)  
  8. Console.Write(progress)  
  9. Console.ForegroundColor =originalForegroundColor 
  10. Console.BackgroundColor = originalBackgroundColor 
  11. End Sub  

首先,该代码保存当前的前景和背景颜色。然后,它把ForegroundColor属性设置为黑色,把BackgroundColor属性设置为绿色。在把光标放置到进度条的左边缘后,它打印一串长度为m_currentBarLength的“O”。

其它问题

这个DirCopy应用程序,虽然有些用处,但是还远非成品。为了使其更为强壮,还需要增加大量的错误处理方式。你还可以改进ConsoleProgressBar类以实现更灵活的控制。下列是一些可能的改进:
◆允许控制进度条的位置和长度
◆允许百分比完成区域放到你选择的任何位置
◆允许定制进度条中的消息
◆添加一个选项以选择水平的或垂直的进度条

【编辑推荐】

  1. VB 2005中开发新一代控制台应用程序
  2. 简单讲解VB开发分布式
  3. 浅析VB Script开发自动化测试
  4. 浅谈VB开发系统知识
  5. VB.NET应用程序中多线程的应用实例
责任编辑:佚名 来源: 比特网
相关推荐

2009-10-28 10:06:29

VB.NET With

2009-10-10 15:19:43

VB.NET Web

2009-10-12 15:41:09

VB.NET动态代码

2009-09-25 14:23:39

2009-09-28 10:39:01

Hibernate基础

2010-01-07 17:00:38

VB.NET控件数组

2009-10-14 10:25:52

VB.NET读写文本文

2009-09-09 09:48:43

Linq延迟加载

2009-06-18 14:00:51

2009-09-14 16:21:34

LINQ To XML

2009-09-08 15:56:50

Linq使用Group

2009-09-14 13:50:35

LINQ编程模型

2009-11-20 13:11:44

Oracle XML数

2010-01-06 13:50:37

.NET Framew

2009-12-07 15:37:00

WCF控件

2009-09-07 13:19:44

C#线程同步

2009-09-04 15:43:07

C#流模型

2010-04-26 18:17:19

Oracle存储过程

2009-09-03 17:57:06

C#声明事件

2009-03-24 08:30:54

AndroidGoogle移动os
点赞
收藏

51CTO技术栈公众号