/// <summary>
/// WinformsコントロールのBegin/EndUpdate等のメソッドをusingブロックによって呼び出すためのクラス
/// </summary>
- public class ControlTransaction
+ public static class ControlTransaction
{
public static IDisposable Update(ListView control)
{
return new Transaction<TreeView>(control, x => x.BeginUpdate(), x => x.EndUpdate());
}
+ public static IDisposable Update(Control control)
+ {
+ // Begin/EndUpdate メソッドを持たないコントロールに対しては、
+ // WM_SETREDRAW メッセージを直接コントロールに送信する。
+ return new Transaction<Control>(control,
+ x => NativeMethods.SetRedrawState(x, false),
+ x => { NativeMethods.SetRedrawState(x, true); x.Invalidate(true); });
+ }
+
public static IDisposable Layout(Control control)
{
return Layout(control, performLayout: true);
return new Transaction<ISupportInitialize>(control, x => x.BeginInit(), x => x.EndInit());
}
+ public static IDisposable Cursor(Control control, Cursor newCursor)
+ {
+ var oldCursor = control.Cursor;
+
+ return new Transaction<Control>(control, x => x.Cursor = newCursor, x => x.Cursor = oldCursor);
+ }
+
+ public static IDisposable Enabled(Control control)
+ {
+ var oldState = control.Enabled;
+
+ return new Transaction<Control>(control, x => x.Enabled = true, x => x.Enabled = oldState);
+ }
+
+ public static IDisposable Disabled(Control control)
+ {
+ var oldState = control.Enabled;
+
+ return new Transaction<Control>(control, x => x.Enabled = false, x => x.Enabled = oldState);
+ }
+
private class Transaction<T> : IDisposable
{
private readonly T control;