Widow – Blame information for rev 11

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  
38 public static void Execute(this Control control, Action lambda)
39 {
40 if (control.InvokeRequired)
41 {
42 control.Invoke((MethodInvoker) lambda.Invoke);
43 }
44 else
45 {
46 lambda.Invoke();
47 }
48 }
49  
1 office 50 public static bool Set(bool enable)
51 {
52 using (var key = Registry.CurrentUser.OpenSubKey
53 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
54 {
55 if (key == null)
56 {
57 return false;
58 }
59  
60 switch (enable)
61 {
62 case true:
63 key.SetValue(Constants.AssemblyName, Assembly.GetEntryAssembly().Location);
64 break;
65 default:
66 key.DeleteValue(Constants.AssemblyName, false);
67 break;
68 }
69 }
70  
71 return true;
72 }
73  
74 public static bool Get()
75 {
76 using (var key = Registry.CurrentUser.OpenSubKey
77 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
78 {
79 return key?.GetValue(Constants.AssemblyName) != null;
80 }
81 }
82  
83 #endregion
84 }
85 }