-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimerForm.cs
126 lines (105 loc) · 3.16 KB
/
timerForm.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
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.Windows.Forms;
using System.Diagnostics;
using ResizeControl;
namespace JDL_Curtain
{
public partial class timerForm : Form
{
// Used for dragging the windows
bool isDragging = false;
int draggingX = 0;
int draggingY = 0;
// Whether to use miliseconds or not
bool useMiliseconds = false;
Stopwatch stopWatch = new Stopwatch();
public timerForm()
{
InitializeComponent();
}
private void topBar_MouseDown(object sender, MouseEventArgs e)
{
isDragging = true;
draggingX = MousePosition.X - this.Location.X;
draggingY = MousePosition.Y - this.Location.Y;
}
private void topBar_MouseMove(object sender, MouseEventArgs e)
{
Control c = (Control)sender;
if (isDragging && c.Cursor == Cursors.Default)
{
this.Location = new Point(MousePosition.X - draggingX, MousePosition.Y - draggingY);
}
}
private void topBar_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}
private void exitBtn_MouseEnter(object sender, EventArgs e)
{
Label thisLabel = (Label)sender;
thisLabel.BackColor = Color.Azure;
}
private void exitBtn_MouseLeave(object sender, EventArgs e)
{
Label thisLabel = (Label)sender;
thisLabel.BackColor = topBar.BackColor;
}
private void exitBtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void startTimerBtn_Click(object sender, EventArgs e)
{
stopWatch.Start();
updateTimer.Enabled = true;
startTimerBtn.Enabled = false;
stopTimerBtn.Enabled = true;
}
private void stopTimerBtn_Click(object sender, EventArgs e)
{
stopWatch.Stop();
updateTimeLabel();
updateTimer.Enabled = false;
startTimerBtn.Enabled = true;
stopTimerBtn.Enabled = false;
}
private void resetTimerBtn_Click(object sender, EventArgs e)
{
stopWatch.Reset();
updateTimeLabel();
updateTimer.Enabled = false;
startTimerBtn.Enabled = true;
stopTimerBtn.Enabled = false;
}
private void updateTimer_Tick(object sender, EventArgs e)
{
updateTimeLabel();
}
private void timeLabel_DoubleClick(object sender, EventArgs e)
{
useMiliseconds = !useMiliseconds;
updateTimeLabel();
}
private void timerForm_Load(object sender, EventArgs e)
{
ResizableControl f = new ResizableControl();
Control[] children = { topBar, topBarTitle, mainContainer };
f.MakeControlResizable(this, 10, children, ResizeLocation.Bottom | ResizeLocation.Right | ResizeLocation.BottomRight, this.Size, new Size(Screen.FromControl(this).Bounds.Width, Screen.FromControl(this).Bounds.Height));
}
private void updateTimeLabel()
{
if (useMiliseconds)
timeLabel.Text = String.Format("{0:00}:{1:00}:{2:00}", stopWatch.Elapsed.Minutes, stopWatch.Elapsed.Seconds, stopWatch.Elapsed.Milliseconds / 10);
else
timeLabel.Text = String.Format("{0:00}:{1:00}", stopWatch.Elapsed.Minutes, stopWatch.Elapsed.Seconds);
}
}
}