// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.
+#nullable enable
+
using System;
using System.Collections.Generic;
using System.Linq;
public static class ControlTransaction
{
public static IDisposable Update(ListView control)
- {
- return new Transaction<ListView>(control, x => x.BeginUpdate(), x => x.EndUpdate());
- }
+ => new Transaction<ListView>(control, x => x.BeginUpdate(), x => x.EndUpdate());
public static IDisposable Update(ListBox control)
- {
- return new Transaction<ListBox>(control, x => x.BeginUpdate(), x => x.EndUpdate());
- }
+ => new Transaction<ListBox>(control, x => x.BeginUpdate(), x => x.EndUpdate());
public static IDisposable Update(ComboBox control)
- {
- return new Transaction<ComboBox>(control, x => x.BeginUpdate(), x => x.EndUpdate());
- }
+ => new Transaction<ComboBox>(control, x => x.BeginUpdate(), x => x.EndUpdate());
public static IDisposable Update(TreeView control)
- {
- return new Transaction<TreeView>(control, x => x.BeginUpdate(), x => x.EndUpdate());
- }
+ => new Transaction<TreeView>(control, x => x.BeginUpdate(), x => x.EndUpdate());
public static IDisposable Update(Control control)
{
}
public static IDisposable Layout(Control control)
+ => Layout(control, performLayout: true);
+
+ public static IDisposable Layout(Control control, bool performLayout)
+ => new Transaction<Control>(control, x => x.SuspendLayout(), x => x.ResumeLayout(performLayout));
+
+ public static IDisposable Init(ISupportInitialize control)
+ => new Transaction<ISupportInitialize>(control, x => x.BeginInit(), x => x.EndInit());
+
+ public static IDisposable Cursor(Control control, Cursor newCursor)
{
- return Layout(control, performLayout: true);
+ var oldCursor = control.Cursor;
+
+ return new Transaction<Control>(control, x => x.Cursor = newCursor, x => x.Cursor = oldCursor);
}
- public static IDisposable Layout(Control control, bool performLayout)
+ public static IDisposable Enabled(Control control)
{
- return new Transaction<Control>(control, x => x.SuspendLayout(), x => x.ResumeLayout(performLayout));
+ var oldState = control.Enabled;
+
+ return new Transaction<Control>(control, x => x.Enabled = true, x => x.Enabled = oldState);
}
- public static IDisposable Init(ISupportInitialize control)
+ public static IDisposable Disabled(Control control)
{
- return new Transaction<ISupportInitialize>(control, x => x.BeginInit(), x => x.EndInit());
+ var oldState = control.Enabled;
+
+ return new Transaction<Control>(control, x => x.Enabled = false, x => x.Enabled = oldState);
}
private class Transaction<T> : IDisposable
}
public void Dispose()
- {
- this.endTransaction(this.control);
- }
+ => this.endTransaction(this.control);
}
}
}