-
Notifications
You must be signed in to change notification settings - Fork 12
/
Tray.cs
108 lines (89 loc) · 3.22 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
/* AeroShot - Transparent screenshot utility for Windows
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 Mini";
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 Alt+PrtSrn to Capture Screenshots", "Screenshot will be save 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);
}
}
}