forked from toehead2001/aeroshot
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Tray.cs
121 lines (100 loc) · 3.53 KB
/
Tray.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
/* AeroShot - Transparent screenshot utility for Windows
Copyright (C) 2021 Cvolton
Copyright (C) 2015 toe_head2001
AeroShot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
AeroShot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
using System;
using System.Drawing;
using System.Windows.Forms;
namespace AeroShot
{
public class SysTray : Form
{
private NotifyIcon trayIcon;
private ContextMenu trayMenu;
MainForm _window = new MainForm();
Hotkeys _hotkeys = new Hotkeys();
Settings _settings = new Settings();
public SysTray()
{
trayIcon = new NotifyIcon();
trayIcon.Text = "AeroShot CRE";
Icon _trayIcon = new Icon(typeof(SysTray), "icon.ico");
trayIcon.Icon = new Icon(_trayIcon, 16, 16);
// Create a tray menu
trayMenu = new ContextMenu();
trayMenu.MenuItems.Add("Settings...", ShowWindow);
trayMenu.MenuItems.Add("-");
trayMenu.MenuItems.Add("Exit", OnExit);
// Add menu to tray icon and show it.
trayIcon.ContextMenu = trayMenu;
trayIcon.Visible = true;
// Handle the DoubleClick event to open the Settings window.
trayIcon.DoubleClick += ShowWindow;
}
protected override void OnLoad(EventArgs e)
{
Visible = false; // Hide form window.
ShowInTaskbar = false; // Remove from taskbar.
base.OnLoad(e);
string saveLocation;
if (_settings.diskButton)
{
saveLocation = "\"" + _settings.folderTextBox + "\"";
}
else
{
saveLocation = "the Clipboard";
}
trayIcon.ShowBalloonTip(10000, $"Press {KeyHelpers.modifiers[_settings.hotkeyModifier]} + {((Keys)_settings.hotkeyKey).ToString()} to Capture Screenshots", "Screenshot will be saved to " + saveLocation + ".", ToolTipIcon.Info);
}
private void OnExit(object sender, EventArgs e)
{
_hotkeys.Close(); //unregisters the hotkeys on program exit
Application.Exit();
}
private void ShowWindow(object sender, EventArgs e)
{
if (_window.IsDisposed)
{
_window = new MainForm();
_window.Show();
}
else
{
if (!_window.Visible)
{
_window.Show();
}
}
_window.Activate();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
// Release the icon resource.
trayIcon.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// SysTray
//
this.ClientSize = new System.Drawing.Size(284, 261);
this.Name = "SysTray";
this.ResumeLayout(false);
}
}
}