Windows 窗体 ProgressBar 控件通过在水平条中显示适当数目的矩形来指示进程的进度。进程完成时,进度栏被填满。进度栏通常用于帮助用户了解等待一项长时间的进程(例如,加载大文件)完成所需的时间。ProgressBar 控件的主要属性为 Value、Minimum 和 Maximum。Minimum 和 Maximum 属性设置进度条可以显示的最大值和最小值——最小值由一个矩形表示。若要更新当前的进度值,必须编写代码来设置 Value 属性。在加载大文件的例子中,可将最大值设置为以 KB 为单位的文件大小。如果将 Maximum 属性设置为 100,将 Minimum 属性设置为 10,并且将 Value 属性设置为 50,则将显示 5 个矩形——这是可以显示的矩形个数的一半。

解决方案 »

  1.   

    private void CopyWithProgress(string[] filenames)
          {
             // Display the ProgressBar control.
             pBar1.Visible = true;
             // Set Minimum to 1 to represent the first file being copied.
             pBar1.Minimum = 1;
             // Set Maximum to the total number of files to copy.
             pBar1.Maximum = filenames.Length;
             // Set the initial value of the ProgressBar.
             pBar1.Value = 1;
             // Set the Step property to a value of 1 to represent each file being copied.
             pBar1.Step = 1;
             
             // Loop through all files to copy.
             for (int x = 1; x <= filenames.Length; x++)
             {
                // Copy the file and increment the ProgressBar if successful.
                if(CopyFile(filenames[x-1]) == true)
                {
                   // Perform the increment on the ProgressBar.
                   pBar1.PerformStep();
                }
             }
          }
    [C++, JScript] 没有可用于 C++ 或 JScript 的示例。若要查看 Visual Basic 或 C# 示例,请单击页左上角的语言筛选器按钮 。
      

  2.   

    用 ProgressBar  控件。
    可以指定开始值
    ProgressBar .Minimum
    和结束值
    ProgressBar .Maximum
    步长
    ProgressBar.Step
    在运行过程中前进一格
    ProgressBar.PerformStep()