请问各位,C#怎么写一个进度条?有时候加密文件比较大的时候要用的时间也比较长,所以想用一个进度条来显示加密的进度,要进度条自己根据实际显示的那种,小弟初学,不太懂,请各位给出代码研究一下

解决方案 »

  1.   

    ProgressBar
    http://msdn.microsoft.com/zh-cn/library/system.windows.controls.progressbar(VS.95).aspx
      

  2.   

    1.先必须声明一个委托
     delegate void ShowProgressDelegate(int minStep, int totalStep, int currentStep);
    2.写一个对于的方法来调用委托
       // 显示进度条
        void ShowProgress(int minStep, int totalStep, int currentStep)
     {
                this.tspsBoxBar.Minimum = minStep;
                this.tspsBoxBar.Maximum = totalStep;
                this.tspsBoxBar.Value = currentStep;
                this.xftslblValue.Text = 100 * currentStep / totalStep + "%";
                (lbl显示的百分数)
      } 
      3.添加一个ProgressBar(进度条)
      4.将方法实例化为委托
           ShowProgressDelegate showProgress = new ShowProgressDelegate(ShowProgress);
       // 显示进度条
      this.Invoke(showProgress, new object[] { startCode, endCode, i });
      

  3.   

    加密文件比较大,这就是个思路啥。
     直接得到加密文件byte的length,
                      progressBar.Maximum = length ;
                    progressBar.Minimum = 0;
                    progressBar.Value = 0;
     
    然后while循环往stream写的时候就progressBar.Value+=10啊8的随便你。要是快,就不显示,慢就会显示出来。
      

  4.   

    楼主,你去书上找关于控件ProgressBar的知识看看,肯定会了。顶一个,一起学习之!
      

  5.   

    看一下winform 之类的书  肯定就会了
      

  6.   

    ProgressBar 楼主看看它的用法就知道怎么弄了。。