-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
128 lines (115 loc) · 3.8 KB
/
MainWindow.xaml.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
127
128
// <copyright file="MainWindow.xaml.cs" company="AirOsprey">
// MIT License (MIT). All rights reserved
// </copyright>
// <author>Larry Conklin</author>
// <summary>This is the MainWindow class.</summary>
using System;
using System.Timers;
using System.Windows;
using System.Windows.Forms;
namespace BlueDot
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private static System.Timers.Timer blink;
private static System.Windows.Forms.NotifyIcon ni;
public MainWindow()
{
InitializeComponent();
ni = new System.Windows.Forms.NotifyIcon();
ni.Visible = true;
ni.DoubleClick +=
delegate(object sender, EventArgs args)
{
this.Show();
this.WindowState = WindowState.Normal;
};
}
/// <summary>
/// Key Press.
/// </summary>
public static void KeyPress()
{
SendKeys.SendWait("{F15}");
ni.Visible = true;
}
/// <summary>
/// Set Blink Timing.
/// </summary>
public static void SetBlink()
{
blink = new System.Timers.Timer(2000); // Two second interval.
blink.Elapsed += BlinkEvent;
blink.AutoReset = true;
blink.Enabled = true;
}
/// <summary>
/// State Changed.
/// </summary>
/// <param name="e">Event Args.</param>
protected override void OnStateChanged(EventArgs e)
{
if (WindowState == WindowState.Minimized)
{
this.Hide();
}
base.OnStateChanged(e);
}
/// <summary>
/// State Changed.
/// </summary>
/// <param name="source">System object.</param>
/// <param name="e">Elapsed event args.</param>
private static void BlinkEvent(Object source, ElapsedEventArgs e)
{
ni.Visible = false;
KeyPress();
}
/// <summary>
/// Exit program via menu option.
/// </summary>
/// <param name="sender">Object source.</param>
/// <param name="e">Routed event args.</param>
private void mnuNew_Exit(object sender, RoutedEventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
/// <summary>
/// About window box via menu option.
/// </summary>
/// <param name="sender">Object source.</param>
/// <param name="e">Routed event args.</param>
private void MenuItem_About(object sender, RoutedEventArgs e)
{
About about = new About();
about.IsSemanticVersioning = true;
about.HyperlinkText = "https://github.com/lwconklin";
about.Show();
}
/// <summary>
/// Start program button.
/// </summary>
/// <param name="sender">Object source.</param>
/// <param name="e">Routed event args.</param>
private void StartButton_Click(object sender, RoutedEventArgs e)
{
SetBlink();
this.WindowState = WindowState.Minimized;
}
/// <summary>
/// Stop program button.
/// </summary>
/// <param name="sender">Object source.</param>
/// <param name="e">Routed event args.</param>
private void StopButton_Click(object sender, RoutedEventArgs e)
{
blink.Stop();
blink.Close();
blink.Dispose();
this.WindowState = WindowState.Minimized;
}
}
}