-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
72 lines (66 loc) · 2.04 KB
/
Form1.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AlarmApplication
{
public partial class Form1 : Form
{
System.Timers.Timer timer;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer = new System.Timers.Timer();
timer.Interval = 1000;
timer.Elapsed += Timer_Elapsed;
}
delegate void UpdateLabel(Label lbl, string value);
void UpdateDataLabel(Label lbl, string value)
{
lbl.Text = value;
}
private void Timer_Elapsed(object sender, EventArgs e)
{
DateTime currentTime = DateTime.Now;
DateTime userTime = dateTimePicker.Value;
if(currentTime.Hour == userTime.Hour && currentTime.Minute == userTime.Minute && currentTime.Second == userTime.Second)
{
timer.Stop();
try
{
UpdateLabel upd = UpdateDataLabel;
if (lblStatus.InvokeRequired)
{
Invoke(upd, lblStatus, "Stop");
}
SoundPlayer player = new SoundPlayer();
player.SoundLocation = @"C:\Windows\Media\Alarm01.wav";
player.PlayLooping();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
private void btnStart_Click(object sender, EventArgs e)
{
timer.Start();
lblStatus.Text = "Runing";
}
private void btnStop_Click(object sender, EventArgs e)
{
timer.Stop();
lblStatus.Text = "Stop";
}
}
}