Widow
/trunk/Widow/Utilities.cs |
@@ -1,4 +1,6 @@ |
using System.Reflection; |
using System; |
using System.Reflection; |
using System.Windows.Forms; |
using Microsoft.Win32; |
|
namespace Widow |
@@ -7,6 +9,43 @@ |
{ |
#region Public Methods |
|
/// <summary> |
/// Enable double buffering for an arbitrary control. |
/// </summary> |
/// <param name="control">the control to enable double buffering for</param> |
/// <returns>true on success</returns> |
/// <remarks>Do not enable double buffering on RDP: https://devblogs.microsoft.com/oldnewthing/20060103-12/?p=32793</remarks> |
public static bool SetDoubleBuffered(this Control control) |
{ |
if (SystemInformation.TerminalServerSession) |
{ |
return false; |
} |
|
var dgvType = control.GetType(); |
var pi = dgvType.GetProperty("DoubleBuffered", |
BindingFlags.Instance | BindingFlags.NonPublic); |
if (pi == null) |
{ |
return false; |
} |
|
pi.SetValue(control, true, null); |
|
return true; |
} |
|
public static void InvokeIfRequired<T>(this T control, Action<T> action) where T : Control |
{ |
if (control.InvokeRequired) |
{ |
control.BeginInvoke((MethodInvoker) delegate { action(control); }); |
return; |
} |
|
action(control); |
} |
|
public static bool Set(bool enable) |
{ |
using (var key = Registry.CurrentUser.OpenSubKey |