WaitCursorChanger.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Windows.Forms;
  3. namespace PaintDotNet
  4. {
  5. /// <summary>
  6. /// Simply sets a control's Cursor to the WaitCursor (hourglass) on creation,
  7. /// and sets it back to its original setting upon disposal.
  8. /// </summary>
  9. public sealed class WaitCursorChanger
  10. : IDisposable
  11. {
  12. private Control control;
  13. private Cursor oldCursor;
  14. private static int nextID = 0;
  15. private int id = System.Threading.Interlocked.Increment(ref nextID);
  16. public WaitCursorChanger(Control control)
  17. {
  18. this.control = control;
  19. this.oldCursor = Cursor.Current;
  20. Cursor.Current = Cursors.WaitCursor;
  21. }
  22. ~WaitCursorChanger()
  23. {
  24. Dispose(false);
  25. }
  26. public void Dispose()
  27. {
  28. Dispose(true);
  29. GC.SuppressFinalize(this);
  30. }
  31. private void Dispose(bool disposing)
  32. {
  33. if (disposing)
  34. {
  35. if (this.oldCursor != null)
  36. {
  37. Cursor.Current = this.oldCursor;
  38. this.oldCursor = null;
  39. }
  40. }
  41. }
  42. }
  43. }