-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
87 lines (74 loc) · 2.43 KB
/
MainForm.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
using DecolorizerWindow.Properties;
using static DecolorizerWindow.Core;
namespace DecolorizerWindow
{
public partial class MainForm : Form
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= WS_EX_TRANSPARENT;
return cp;
}
}
private readonly GlobalKeyboardHook globalKeyboardHook;
public MainForm()
{
InitializeComponent();
Core.MainForm = this;
if (Core.Width == 0)
{
Core.Width = (ushort)(Screen.PrimaryScreen.Bounds.Width * 0.3);
Core.Height = (ushort)(Screen.PrimaryScreen.Bounds.Height * 0.3);
Settings.Default.Save();
}
globalKeyboardHook = new(new[] { Keys.Z });
globalKeyboardHook.KeyboardPressed += OnKeyboardPressed;
MakeFormInvisible(this);
StartUpdating();
}
private async void OnKeyboardPressed(object sender, GlobalKeyboardHookEventArgs e)
{
if (e.KeyboardState == GlobalKeyboardHook.KeyboardState.SysKeyDown)
{
if (e.KeyboardData.Key == Keys.Z && (ModifierKeys & Keys.Alt) != 0)
await ToggleProgramState();
}
}
private void trayIcon_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
OpenSettings();
}
private void toggleDisplayMenuItem_Click(object sender, EventArgs e)
{
_ = ToggleProgramState();
}
private void settingsMenuItem_Click(object sender, EventArgs e)
{
OpenSettings();
}
private async void exitMenuItem_Click(object sender, EventArgs e)
{
await StopUpdating(showError: false);
Application.Exit();
}
private void OpenSettings()
{
foreach (var form in Application.OpenForms)
{
if (form is SettingsForm setForm)
{
setForm.WindowState = FormWindowState.Normal;
setForm.BringToFront();
setForm.Focus();
return;
}
}
SettingsForm settingsForm = new();
settingsForm.Show();
}
}
}