-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainForm.cs
126 lines (107 loc) · 3.66 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowTool
{
public partial class MainForm : Form
{
HotkeyHandler hotkeyHandler;
public MainForm()
{
InitializeComponent();
hotkeyHandler = new HotkeyHandler();
hotkeyHandler.Start();
Application.ApplicationExit += Application_ApplicationExit;
iconMenuItem.Checked = Properties.Settings.Default.AltIcon;
bool isClamped = Properties.Settings.Default.ClampedToScreen;
handleSetClampToScreen(isClamped);
HideForm();
}
private void Application_ApplicationExit(object sender, EventArgs e)
{
hotkeyHandler.Stop();
}
private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
HideForm();
}
}
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
clampMenuItem.Checked = !clampMenuItem.Checked;
clampMenuItem_Click(this, EventArgs.Empty);
}
private void settingsMenuItem_Click(object sender, EventArgs e)
{
ShowForm();
}
private void exitMenuItem_Click(object sender, EventArgs e)
{
notifyIcon.Visible = false;
Application.Exit();
}
private void ShowForm()
{
this.Show();
if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
this.Activate();
}
private void HideForm()
{
this.WindowState = FormWindowState.Minimized;
this.Hide();
}
private void clampMenuItem_Click(object sender, EventArgs e)
{
handleSetClampToScreen(clampMenuItem.Checked);
}
private void iconMenuItem_Click(object sender, EventArgs e)
{
updateIcon();
}
private void handleSetClampToScreen(bool isClamped)
{
Properties.Settings.Default.ClampedToScreen = isClamped;
Properties.Settings.Default.Save();
clampMenuItem.Checked = isClamped;
hotkeyHandler.SetClampToScreen(isClamped);
updateIcon();
/*
if (isClamped)
{
notifyIcon.Icon = iconMenuItem.Checked ? Properties.Resources.ClampTrue : Properties.Resources.AltClampTrue;
//notifyIcon.Icon = WindowTool.Properties.Resources.AltClampTrue;
}
else
{
notifyIcon.Icon = iconMenuItem.Checked ? Properties.Resources.ClampFalse : Properties.Resources.AltClampFalse;
//notifyIcon.Icon = WindowTool.Properties.Resources.AltClampFalse;
}
*/
}
private void updateIcon()
{
Properties.Settings.Default.AltIcon = iconMenuItem.Checked;
Properties.Settings.Default.Save();
if (clampMenuItem.Checked)
{
notifyIcon.Icon = iconMenuItem.Checked ? Properties.Resources.AltClampTrue : Properties.Resources.ClampTrue;
}
else
{
notifyIcon.Icon = iconMenuItem.Checked ? Properties.Resources.AltClampFalse : Properties.Resources.ClampFalse;
}
}
}
}