-
Notifications
You must be signed in to change notification settings - Fork 0
/
MailPopUp.cs
135 lines (121 loc) · 3.31 KB
/
MailPopUp.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
129
130
131
132
133
134
135
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace MailPopUp
{
/// <summary>
/// Summary description for MailPopUp.
/// </summary>
public class MailPopUp : System.Windows.Forms.Form
{
private NotifyIcon tIcon;
private Timer CheckTimer;
private MailChecker mailSystem;
private System.ComponentModel.Container components = null;
public MailPopUp()
{
InitializeComponent();
mailSystem = new MailChecker();
tIcon = new NotifyIcon();
tIcon.Icon =
new System.Drawing.Icon (@".\Mail.ico");
tIcon.Visible = true;
tIcon.Text = "Mail Pop-Up";
tIcon.ContextMenu = new ContextMenu();
tIcon.ContextMenu.MenuItems.Add("Settings", new System.EventHandler(this.Icon_Settings));
tIcon.ContextMenu.MenuItems.Add("Start", new System.EventHandler(this.Icon_Start));
tIcon.ContextMenu.MenuItems.Add("Stop", new System.EventHandler(this.Icon_Stop));
tIcon.ContextMenu.MenuItems.Add("-");
tIcon.ContextMenu.MenuItems.Add("Exit", new System.EventHandler(this.Icon_Exit));
CheckTimer = new Timer();
CheckTimer.Enabled = true;
CheckTimer.Tick += new EventHandler(CheckTimer_Tick);
CheckTimer.Stop();
Form sForm = new Settings(this);
sForm.ShowDialog();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
tIcon.Visible = false;
tIcon.Dispose();
}
base.Dispose( disposing );
}
//Application Entry Point
[STAThread]
static void Main()
{
Application.Run(new MailPopUp());
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// MailPopUp
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(264, 142);
this.Enabled = false;
this.Name = "MailPopUp";
this.ShowInTaskbar = false;
this.Text = "MailPopUp";
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
}
#endregion
private void CheckTimer_Tick(object Sender, EventArgs e)
{
mailSystem.CheckMail();
//For debugging purposes only:
//CheckTimer.Stop();
}
//Event Handlers for menu options that appear in the pop-up menu on the Taskbar
private void Icon_Settings(object sender, System.EventArgs e)
{
Form sForm = new Settings(this);
sForm.ShowDialog();
}
private void Icon_Start(object sender, System.EventArgs e)
{
StartTimer();
}
private void Icon_Stop(object sender, System.EventArgs e)
{
CheckTimer.Stop();
}
private void Icon_Exit(object sender, System.EventArgs e)
{
CheckTimer.Stop();
this.Close();
}
//Start a timer to check for messages periodically
public void StartTimer()
{
string timeUnit = mailSystem.Units;
if(timeUnit == "Hours")
CheckTimer.Interval = mailSystem.Interval * 3600000;
else if(timeUnit == "Minutes")
CheckTimer.Interval = mailSystem.Interval * 60000;
else //Assume Seconds
CheckTimer.Interval = mailSystem.Interval * 1000;
if(CheckTimer.Interval > 0)
CheckTimer.Start();
else
{
Form sForm = new Settings();
sForm.ShowDialog();
}
}
}
}