-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStopwatch.cs
64 lines (56 loc) · 1.48 KB
/
Stopwatch.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Timer
{
class Stopwatch
{
System.Windows.Forms.Label label;
private Int64 start_msec;
private Int64 msec;
private bool running;
public Stopwatch(System.Windows.Forms.Label label)
{
this.label = label;
StopReset();
}
public bool IsRunning()
{
return running;
}
public void StopReset()
{
Stop();
this.msec = 0;
label.Text = "00:00.00";
}
public void Stop()
{
this.running = false;
}
public void Start()
{
this.start_msec = System.DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
this.running = true;
}
public int GetTime()
{
return (int)this.msec;
}
public void Step()
{
if(this.running)
{
this.msec = System.DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - this.start_msec;
int fms = (int)(this.msec / 10);
int hun = fms % 100;
fms = (fms - hun) / 100;
int sec = fms % 60;
fms = (fms - sec) / 60;
int min = fms;
label.Text = min.ToString("D2") + ":" + sec.ToString("D2") + "." + hun.ToString("D2");
}
}
}
}