OSDN Git Service

コレクション初期化子を使用する (IDE0028)
[opentween/open-tween.git] / OpenTween / ControlTransaction.cs
index 99f37a4..599710f 100644 (file)
@@ -31,7 +31,7 @@ namespace OpenTween
     /// <summary>
     /// WinformsコントロールのBegin/EndUpdate等のメソッドをusingブロックによって呼び出すためのクラス
     /// </summary>
-    public class ControlTransaction
+    public static class ControlTransaction
     {
         public static IDisposable Update(ListView control)
         {
@@ -53,6 +53,15 @@ namespace OpenTween
             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);
@@ -68,6 +77,27 @@ namespace OpenTween
             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;