Posted By

yesraaj on 01/04/11


Tagged

hourglass


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

cybermax
ovuncgursoy


Hour glass


 / Published in: C#
 

  1. public class HourGlass : IDisposable
  2. {
  3. public HourGlass()
  4. {
  5. Enabled = true;
  6. }
  7. public Boolean Enabled
  8. {
  9.  
  10. get { return Application.UseWaitCursor; }
  11. set
  12. {
  13. if (value != Application.UseWaitCursor)
  14. {
  15. Application.UseWaitCursor = value;
  16. Form f = Form.ActiveForm;
  17. if (f != null && f.Handle != null)
  18. {
  19. //Send WM_SETCURSOR message
  20. SendMessage(f.Handle, 0x20, f.Handle, (IntPtr)1);
  21. }
  22. }
  23. }
  24. }
  25. [System.Runtime.InteropServices.DllImport("user32.dll")]
  26. private static extern IntPtr SendMessage(IntPtr hWind,int msg,IntPtr wp, IntPtr lp);
  27.  
  28. #region IDisposable Members
  29.  
  30. void IDisposable.Dispose()
  31. {
  32. Enabled = false;
  33. }
  34.  
  35. #endregion
  36. }
  37.  
  38. //Usage
  39. using (new HourGlass())
  40. {
  41. //time consuming code goes here
  42. }

Report this snippet  

You need to login to post a comment.