如题,用C#实现一个WinForm的窗体,里面就有一个进度条就行
主要是进度条和Timer结合实现文件的拷贝功能,
希望高手发个简单的代码。
谢谢!

解决方案 »

  1.   

    btnCopy的click事件代码:
    {
    Thread th = new Thread(new ThreadStart(Copy1));
                th.Start();
    }拷贝方法:
    void Copy1()
    {
    int intTotalFiles=0,intCurrent=0;
    intTotalFiles=获取文件总数方法();
    成功拷贝一个文件();intCurrent++;
    progressBar1.Value=100*(intCurrent/intTotalFiles);
    }
      

  2.   

    以前的一个类似贴子的问题的回答先转化成流,利用Stream.Length   属性   
    根据:已传输的流长度/文件长度设定process
     using   System;   
      using   System.IO;   
      class   MyStream     
      {   
              private   const   string   FILE_NAME   =   "Test.data";   
              public   static   void   Main(String[]   args)     
              {   
                      //   Create   the   new,   empty   data   file.   
                      if   (File.Exists(FILE_NAME))     
                      {   
                              Console.WriteLine("{0}   already   exists!",   FILE_NAME);   
                              return;   
                      }   
                      FileStream   fs   =   new   FileStream(FILE_NAME,   FileMode.CreateNew);   
                      //   Create   the   writer   for   data.   
                      BinaryWriter   w   =   new   BinaryWriter(fs);   
                      //   Write   data   to   Test.data.   
                      for   (int   i   =   0;   i   <   11;   i++)     
                      {   
                              w.Write(   (int)   i);   
                              //此处设定ProcessBar的position为   i/11*100%   
                      }   
                      w.Close();   
                      fs.Close();   
                      //   Create   the   reader   for   data.   
                      fs   =   new   FileStream(FILE_NAME,   FileMode.Open,   FileAccess.Read);   
                      BinaryReader   r   =   new   BinaryReader(fs);   
                      //   Read   data   from   Test.data.   
                      for   (int   i   =   0;   i   <   11;   i++)     
                      {   
                              Console.WriteLine(r.ReadInt32());   
                      }   
                      w.Close();   
              }   
      }   
      

  3.   

    自己写太订烦了,记得在VS2005 Beta版的时候有个函数直接调用Explore的文件复制,移动的功能,还能显示资源管理器的标准进度框,现在到VS2005的正式版里不知为什么给卡掉了。找了半天才找到原始的API函数 SHFileOperation在shell32.dll里,参数和用法嘛,说明太多了,参考MSDN吧。