Widow – Blame information for rev 21

Subversion Repositories:
Rev:
Rev Author Line No. Line
11 office 1 using System;
2 using System.Reflection;
3 using System.Windows.Forms;
1 office 4 using Microsoft.Win32;
5  
6 namespace Widow
7 {
8 public static class LaunchOnBoot
9 {
10 #region Public Methods
11  
11 office 12 /// <summary>
13 /// Enable double buffering for an arbitrary control.
14 /// </summary>
15 /// <param name="control">the control to enable double buffering for</param>
16 /// <returns>true on success</returns>
17 /// <remarks>Do not enable double buffering on RDP: https://devblogs.microsoft.com/oldnewthing/20060103-12/?p=32793</remarks>
18 public static bool SetDoubleBuffered(this Control control)
19 {
20 if (SystemInformation.TerminalServerSession)
21 {
22 return false;
23 }
24  
25 var dgvType = control.GetType();
26 var pi = dgvType.GetProperty("DoubleBuffered",
27 BindingFlags.Instance | BindingFlags.NonPublic);
28 if (pi == null)
29 {
30 return false;
31 }
32  
33 pi.SetValue(control, true, null);
34  
35 return true;
36 }
37  
21 office 38 public static void InvokeIfRequired<T>(this T control, Action<T> action) where T : Control
11 office 39 {
40 if (control.InvokeRequired)
41 {
21 office 42 control.BeginInvoke((MethodInvoker) delegate { action(control); });
43 return;
11 office 44 }
21 office 45  
46 action(control);
11 office 47 }
48  
1 office 49 public static bool Set(bool enable)
50 {
51 using (var key = Registry.CurrentUser.OpenSubKey
52 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
53 {
54 if (key == null)
55 {
56 return false;
57 }
58  
59 switch (enable)
60 {
61 case true:
62 key.SetValue(Constants.AssemblyName, Assembly.GetEntryAssembly().Location);
63 break;
64 default:
65 key.DeleteValue(Constants.AssemblyName, false);
66 break;
67 }
68 }
69  
70 return true;
71 }
72  
73 public static bool Get()
74 {
75 using (var key = Registry.CurrentUser.OpenSubKey
76 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
77 {
78 return key?.GetValue(Constants.AssemblyName) != null;
79 }
80 }
81  
82 #endregion
83 }
84 }