-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
134 lines (111 loc) · 4.17 KB
/
Form1.cs
File metadata and controls
134 lines (111 loc) · 4.17 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
namespace CountdownTimer
{
public partial class Form1 : Form
{
System.Timers.Timer time;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
time = new System.Timers.Timer();
time.Interval = 1000; // 1 Second
time.Elapsed += OnTimeEvent;
}
private void OnTimeEvent(object sender, ElapsedEventArgs e)
{
Invoke(new Action(() =>
{
// set ones second counter value
onesSecondCounter.Value--;
if (tensMinuteCounter.Value == 0 && onesMinuteCounter.Value == 0 && tensSecondCounter.Value == 0 && onesSecondCounter.Value == -1)
{
onesSecondCounter.Value = 0;
time.Stop();
controlButton.Text = "Start";
onesSecondCounter.Enabled = true;
tensSecondCounter.Enabled = true;
onesMinuteCounter.Enabled = true;
tensMinuteCounter.Enabled = true;
}
else if (onesSecondCounter.Value == -1)
{
onesSecondCounter.Value = 9;
tensSecondCounter.Value--;
}
// set tens second counter value
if (tensMinuteCounter.Value == 0 && onesMinuteCounter.Value == 0 && tensSecondCounter.Value == -1 && onesSecondCounter.Value == 0)
{
tensSecondCounter.Value = 0;
}
else if (tensSecondCounter.Value == -1)
{
tensSecondCounter.Value = 5;
onesMinuteCounter.Value--;
}
// set ones minute counter value
if (tensMinuteCounter.Value == 0 && onesMinuteCounter.Value == -1 && tensSecondCounter.Value == 0 && onesSecondCounter.Value == 0)
{
onesMinuteCounter.Value = 0;
}
else if (onesMinuteCounter.Value == -1)
{
onesMinuteCounter.Value = 9;
tensMinuteCounter.Value--;
}
// set tens minute counter value
if (tensMinuteCounter.Value == -1)
{
tensMinuteCounter.Value = 0;
}
}));
}
private void button1_Click(object sender, EventArgs e)
{
if (controlButton.Text == "Start")
{
if (tensMinuteCounter.Value == -1 && onesMinuteCounter.Value == -1 && tensSecondCounter.Value == -1 && onesSecondCounter.Value == -1)
{
tensMinuteCounter.Value = 0;
onesMinuteCounter.Value = 0;
tensSecondCounter.Value = 0;
onesSecondCounter.Value = 0;
}
else
{
controlButton.Text = "Stop";
onesSecondCounter.Enabled = false;
tensSecondCounter.Enabled = false;
onesMinuteCounter.Enabled = false;
tensMinuteCounter.Enabled = false;
time.Start();
}
}
else
{
time.Stop();
controlButton.Text = "Start";
onesSecondCounter.Enabled = true;
tensSecondCounter.Enabled = true;
onesMinuteCounter.Enabled = true;
tensMinuteCounter.Enabled = true;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
time.Stop();
Application.DoEvents();
}
}
}