Repository navigation
Expand file tree
/
Copy pathCustomTimeForm.cs
More file actions
279 lines (251 loc) · 9.87 KB
/
Copy pathCustomTimeForm.cs
File metadata and controls
279 lines (251 loc) · 9.87 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ReadEye
{
public class CustomTimeForm : Form
{
private RadioButton rbDuration = null!;
private RadioButton rbEndTime = null!;
private NumericUpDown numHours = null!;
private NumericUpDown numMinutes = null!;
private DateTimePicker dtpEndTime = null!;
private Button btnOk = null!;
private Button btnCancel = null!;
// Output results
public bool IsDurationMode { get; private set; } = true;
public TimeSpan SelectedDuration { get; private set; }
public DateTime SelectedEndTime { get; private set; }
private readonly bool defaultToEndTime;
public CustomTimeForm(bool defaultToEndTime = false)
{
this.defaultToEndTime = defaultToEndTime;
InitializeComponent();
}
private void InitializeComponent()
{
this.Text = "Custom Awake Timer - ReadEye";
this.Size = new Size(380, 310);
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.ShowInTaskbar = false;
this.StartPosition = FormStartPosition.CenterScreen;
this.BackColor = Color.FromArgb(28, 28, 28); // Dark Theme Background
this.ForeColor = Color.FromArgb(240, 240, 240);
// Custom Fonts
Font headerFont = new Font("Segoe UI", 12F, FontStyle.Bold);
Font labelFont = new Font("Segoe UI", 10F);
Font inputFont = new Font("Segoe UI", 9.5F);
// Header Title
Label lblTitle = new Label
{
Text = "Custom Awake Timer",
Font = headerFont,
ForeColor = Color.FromArgb(0, 188, 212), // Cyan Accent
Location = new Point(20, 20),
Size = new Size(340, 25),
AutoSize = false
};
this.Controls.Add(lblTitle);
// Horizontal Line
Panel pnlSeparator = new Panel
{
BackColor = Color.FromArgb(50, 50, 50),
Location = new Point(20, 50),
Size = new Size(324, 1)
};
this.Controls.Add(pnlSeparator);
// Option 1: Duration
rbDuration = new RadioButton
{
Text = "For a duration",
Font = labelFont,
Location = new Point(20, 65),
Size = new Size(340, 24),
Checked = !defaultToEndTime
};
rbDuration.CheckedChanged += Option_CheckedChanged;
this.Controls.Add(rbDuration);
// Duration Inputs Panel
Panel pnlDuration = new Panel
{
Location = new Point(45, 95),
Size = new Size(300, 35)
};
this.Controls.Add(pnlDuration);
Label lblHours = new Label
{
Text = "Hours:",
Font = inputFont,
ForeColor = Color.FromArgb(180, 180, 180),
Location = new Point(0, 5),
Size = new Size(50, 20),
TextAlign = ContentAlignment.MiddleLeft
};
numHours = new NumericUpDown
{
Font = inputFont,
BackColor = Color.FromArgb(45, 45, 48),
ForeColor = Color.White,
BorderStyle = BorderStyle.FixedSingle,
Location = new Point(50, 4),
Size = new Size(55, 24),
Minimum = 0,
Maximum = 23,
Value = 0
};
pnlDuration.Controls.Add(lblHours);
pnlDuration.Controls.Add(numHours);
Label lblMinutes = new Label
{
Text = "Mins:",
Font = inputFont,
ForeColor = Color.FromArgb(180, 180, 180),
Location = new Point(125, 5),
Size = new Size(45, 20),
TextAlign = ContentAlignment.MiddleLeft
};
numMinutes = new NumericUpDown
{
Font = inputFont,
BackColor = Color.FromArgb(45, 45, 48),
ForeColor = Color.White,
BorderStyle = BorderStyle.FixedSingle,
Location = new Point(175, 4),
Size = new Size(55, 24),
Minimum = 0,
Maximum = 59,
Value = 30
};
pnlDuration.Controls.Add(lblMinutes);
pnlDuration.Controls.Add(numMinutes);
// Option 2: Target Time
rbEndTime = new RadioButton
{
Text = "Until specific time",
Font = labelFont,
Location = new Point(20, 140),
Size = new Size(340, 24),
Checked = defaultToEndTime
};
rbEndTime.CheckedChanged += Option_CheckedChanged;
this.Controls.Add(rbEndTime);
// Target Time Panel
Panel pnlEndTime = new Panel
{
Location = new Point(45, 170),
Size = new Size(300, 35)
};
this.Controls.Add(pnlEndTime);
Label lblTime = new Label
{
Text = "Time:",
Font = inputFont,
ForeColor = Color.FromArgb(180, 180, 180),
Location = new Point(0, 5),
Size = new Size(50, 20),
TextAlign = ContentAlignment.MiddleLeft
};
dtpEndTime = new DateTimePicker
{
Font = inputFont,
BackColor = Color.FromArgb(45, 45, 48),
ForeColor = Color.White,
Format = DateTimePickerFormat.Time,
ShowUpDown = true,
Location = new Point(50, 4),
Size = new Size(110, 24),
Value = DateTime.Today.AddHours(16.5) // default: 4:30 PM
};
pnlEndTime.Controls.Add(lblTime);
pnlEndTime.Controls.Add(dtpEndTime);
// Cancel Button
btnCancel = new Button
{
Text = "Cancel",
Font = labelFont,
BackColor = Color.FromArgb(60, 60, 60),
ForeColor = Color.FromArgb(220, 220, 220),
FlatStyle = FlatStyle.Flat,
Location = new Point(254, 225),
Size = new Size(90, 32),
DialogResult = DialogResult.Cancel
};
btnCancel.FlatAppearance.BorderSize = 0;
btnCancel.MouseEnter += (s, e) => btnCancel.BackColor = Color.FromArgb(80, 80, 80);
btnCancel.MouseLeave += (s, e) => btnCancel.BackColor = Color.FromArgb(60, 60, 60);
this.Controls.Add(btnCancel);
// OK Button
btnOk = new Button
{
Text = "Start Awake",
Font = labelFont,
BackColor = Color.FromArgb(0, 188, 212),
ForeColor = Color.Black,
FlatStyle = FlatStyle.Flat,
Location = new Point(130, 225),
Size = new Size(115, 32)
};
btnOk.FlatAppearance.BorderSize = 0;
btnOk.MouseEnter += (s, e) => btnOk.BackColor = Color.FromArgb(0, 150, 170);
btnOk.MouseLeave += (s, e) => btnOk.BackColor = Color.FromArgb(0, 188, 212);
btnOk.Click += BtnOk_Click;
this.Controls.Add(btnOk);
this.AcceptButton = btnOk;
this.CancelButton = btnCancel;
// Trigger initial state sync
Option_CheckedChanged(null, EventArgs.Empty);
}
private void Option_CheckedChanged(object? sender, EventArgs e)
{
numHours.Enabled = rbDuration.Checked;
numMinutes.Enabled = rbDuration.Checked;
dtpEndTime.Enabled = rbEndTime.Checked;
if (rbDuration.Checked)
{
numHours.BackColor = Color.FromArgb(45, 45, 48);
numMinutes.BackColor = Color.FromArgb(45, 45, 48);
dtpEndTime.BackColor = Color.FromArgb(35, 35, 35);
}
else
{
numHours.BackColor = Color.FromArgb(35, 35, 35);
numMinutes.BackColor = Color.FromArgb(35, 35, 35);
dtpEndTime.BackColor = Color.FromArgb(45, 45, 48);
}
}
private void BtnOk_Click(object? sender, EventArgs e)
{
IsDurationMode = rbDuration.Checked;
if (IsDurationMode)
{
int hrs = (int)numHours.Value;
int mins = (int)numMinutes.Value;
if (hrs == 0 && mins == 0)
{
MessageBox.Show("Please select a duration greater than 0 minutes.", "Invalid Duration", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
SelectedDuration = new TimeSpan(hrs, mins, 0);
SelectedEndTime = DateTime.Now.Add(SelectedDuration);
}
else
{
DateTime now = DateTime.Now;
DateTime selectedTime = dtpEndTime.Value;
// Create a full DateTime based on today or tomorrow
DateTime targetTime = new DateTime(now.Year, now.Month, now.Day, selectedTime.Hour, selectedTime.Minute, 0);
if (targetTime <= now)
{
// If target time is earlier than current time today, assume tomorrow
targetTime = targetTime.AddDays(1);
}
SelectedEndTime = targetTime;
SelectedDuration = targetTime - now;
}
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}