-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrayApp.cs
70 lines (60 loc) · 1.79 KB
/
TrayApp.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StandUp.Properties;
namespace StandUp
{
class TrayApp : IDisposable
{
NotifyIcon ni;
public TrayApp()
{
// Instantiate the NotifyIcon object.
ni = new NotifyIcon();
}
public void Display()
{
//// Put the icon in the system tray and allow it react to mouse clicks.
ni.MouseClick += new MouseEventHandler(ni_MouseClick);
ni.Icon = Resources.crosswalk;
ni.Text = "StandUp";
ni.Visible = true;
//// Attach a context menu.
ni.ContextMenuStrip = new ContextMenus().Create();
}
public void activate()
{
ni.Icon = Resources.crosswalk_alarm;
ni.ShowBalloonTip(3000, "Stand Up!", "Please take a break for your health.", ToolTipIcon.Info);
}
public void deactivate()
{
ni.Icon = Resources.crosswalk;
}
public void Dispose()
{
// When the application closes, this will remove the icon from the system tray immediately.
System.Console.WriteLine("bye");
ni.Visible = false;
ni.Icon = null;
ni.Dispose();
}
void ni_MouseClick(object sender, MouseEventArgs e)
{
// Handle mouse button clicks.
if (e.Button == MouseButtons.Left)
{
// Show Balloon with ActiveTime and IdleTime
showActiveTime();
}
}
public void showActiveTime()
{
TimeSpan activeSpan = TimeSpan.FromSeconds(Program.atvTimer.getActiveTime());
string activeLabel = activeSpan.ToString(@"hh\:mm\:ss");
ni.ShowBalloonTip(500, "Stand Up!", "Active Time: " + activeLabel + "\n", ToolTipIcon.Info);
}
}
}