用ProgressBar控件实现Copy文件时进度条的显示,如果在窗体时同时显示百分比呀?

解决方案 »

  1.   

    继承ProgressBar, 重写OnPaint,加入描画百分比的逻辑。
      

  2.   

    yourProgressBar.value/yourProgressBar.Maximum *100
      

  3.   

    继承ProgressBar, 重写OnPaint,加入描画百分比的逻辑。
    ProgressBar是sealed class!继承不了!上面的方法不可行!嗬嗬
      

  4.   

    private void CopyWithProgress(string[] filenames)
            {
                // Display the ProgressBar control.
                myBar.Visible = true;
                // Set Minimum to 1 to represent the first file being copied.
                myBar.Minimum = 1;
                // Set Maximum to the total number of files to copy.
                myBar.Maximum = filenames.Length;
                // Set the initial value of the ProgressBar.
                myBar.Value = 1;
                // Set the Step property to a value of 1 to represent each file being copied.
                myBar.Step = 1;            //myBar.Style = ProgressBarStyle.Continuous;            // 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],x) == true)
                    {
                        // Perform the increment on the ProgressBar.
                        myBar.PerformStep();
                       
                        this.label2.Text = Convert.ToString((myBar.Value / Convert.ToDouble(myBar.Maximum)) * 100) + "%";//我在窗体上放了一个Lalbe,调试发现label2.text的值是变了,但是只有当循环执行完了才显示100%
                       
                        
                    }
                               }
            }
      

  5.   

    //我在窗体上放了一个Lalbe,调试发现label2.text的值是变了,但是只有当循环执行完了才显示100%
    你这种做法,中间Form.Update一下应该没问题.
    我觉得想要特殊的外观,自己编一个进度条,没什么难度,完全可以自己做一个,也就是自己处理一下闪屏的问题,现在的双缓存,应该可以解决这个问题,前几年,我看到<四通立方中文平台>的安装进度条,应该是自己用GDI函数绘制的,安装时,闪个没完没了