-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrayIcon.cs
109 lines (93 loc) · 3.54 KB
/
TrayIcon.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Win32;
namespace RoundedWindowsEdges
{
public class TrayIcon : IDisposable
{
private NotifyIcon notifyIcon;
private MainWindow mainWindow;
private ToolStripMenuItem smallCornersItem;
private ToolStripMenuItem mediumCornersItem;
private ToolStripMenuItem largeCornersItem;
private ToolStripMenuItem autoStartItem;
public TrayIcon(MainWindow mainWindow)
{
this.mainWindow = mainWindow;
notifyIcon = new NotifyIcon
{
Icon = Properties.Resources.AppIcon,
Visible = true,
Text = "Rounded Screen"
};
var contextMenu = new ContextMenuStrip();
smallCornersItem = new ToolStripMenuItem("Small Corners", null, (sender, e) => ChangeCornerSize(10));
mediumCornersItem = new ToolStripMenuItem("Medium Corners", null, (sender, e) => ChangeCornerSize(20));
largeCornersItem = new ToolStripMenuItem("Large Corners", null, (sender, e) => ChangeCornerSize(30));
autoStartItem = new ToolStripMenuItem("Auto Start", null, ToggleAutoStart)
{
Checked = IsAutoStartEnabled()
};
contextMenu.Items.Add(smallCornersItem);
contextMenu.Items.Add(mediumCornersItem);
contextMenu.Items.Add(largeCornersItem);
contextMenu.Items.Add(autoStartItem);
contextMenu.Items.Add("Exit", null, OnExit);
notifyIcon.ContextMenuStrip = contextMenu;
UpdateCornerSizeCheck(mainWindow.GetCornerSize());
}
private void ChangeCornerSize(int size)
{
mainWindow.ChangeCornerSize(size);
UpdateCornerSizeCheck(size);
}
private void UpdateCornerSizeCheck(int size)
{
smallCornersItem.Checked = (size == 10);
mediumCornersItem.Checked = (size == 20);
largeCornersItem.Checked = (size == 30);
}
private void ToggleAutoStart(object sender, EventArgs e)
{
var menuItem = sender as ToolStripMenuItem;
if (menuItem != null)
{
if (menuItem.Checked)
{
DisableAutoStart();
menuItem.Checked = false;
}
else
{
EnableAutoStart();
menuItem.Checked = true;
}
}
}
private bool IsAutoStartEnabled()
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
return rk.GetValue("RoundedWindowsEdges") != null;
}
private void EnableAutoStart()
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rk.SetValue("RoundedWindowsEdges", Process.GetCurrentProcess().MainModule.FileName);
}
private void DisableAutoStart()
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rk.DeleteValue("RoundedWindowsEdges", false);
}
private void OnExit(object sender, EventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
public void Dispose()
{
notifyIcon.Dispose();
}
}
}