C# 进度条效果实现实例

C# 进度条效果实现实例是如何的呢?下面让我们看看:

C# 进度条效果实现实例源码:

 
 
 
  1. public class LargeFileCopier  
  2. {  
  3. private const int FO_COPY = 0x02;  
  4. private const int FOF_ALLOWUNDO = 0x40;  
  5. //C# 进度条效果实现实例
  6. [StructLayout(LayoutKind.Sequential,  
  7.  CharSet = CharSet.Auto,Pack=0)]  
  8. public struct SHFILEOPSTRUCT  
  9. {  
  10. public IntPtr hwnd;  
  11. [MarshalAs(UnmanagedType.U4)]  
  12. public int wFunc;  
  13. public string pFrom;  
  14. public string pTo;  
  15. public short fFlags;  
  16. [MarshalAs(UnmanagedType.Bool)]  
  17. public bool fAnyOperationsAborted;  
  18. public IntPtr hNameMappings;  
  19. public string lpszProgressTitle;   
  20.  
  21. }  
  22.  //C# 进度条效果实现实例
  23. [DllImport("shell32.dll",   
  24. CharSet = CharSet.Auto)]  
  25. static extern int SHFileOperation(  
  26. ref SHFILEOPSTRUCT FileOp);  
  27.  
  28. public static bool DoCopy(  
  29. string strSource, string strTarget)  
  30. {  
  31. SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT();  
  32. fileop.wFunc = FO_COPY;  
  33. fileop.pFrom = strSource;  
  34. fileop.pTo = strTarget;  
  35. fileop.fFlags = FOF_ALLOWUNDO;  
  36. SHFileOperation(ref  fileop);  
  37. return !fileop.fAnyOperationsAborted;  
  38. }  
  39. } //C# 进度条效果实现实例  

C# 进度条效果实现实例调用方法:

 
 
 
  1. LargeFileCopier.DoCopy(@"D:\2009-01.exe""f:\2009-01.exe"); 

C# 进度条效果实现实例的基本内容就向你介绍到这里,希望对你了解和学习C# 进度条效果实现实例有所帮助。

【编辑推荐】

  1. C#多线程控制进度条之长任务操作
  2. C#多线程控制进度条之长异步操作
  3. C#多线程控制进度条之异步调用
  4. C#多线程控制进度条之多线程安全
  5. C# listview进度条显示浅析
THE END