using System; using System.Windows.Forms; namespace PaintDotNet { /// /// Simply sets a control's Cursor to the WaitCursor (hourglass) on creation, /// and sets it back to its original setting upon disposal. /// public sealed class WaitCursorChanger : IDisposable { private Control control; private Cursor oldCursor; private static int nextID = 0; private int id = System.Threading.Interlocked.Increment(ref nextID); public WaitCursorChanger(Control control) { this.control = control; this.oldCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; } ~WaitCursorChanger() { Dispose(false); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } private void Dispose(bool disposing) { if (disposing) { if (this.oldCursor != null) { Cursor.Current = this.oldCursor; this.oldCursor = null; } } } } }