-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PromptTimestampDialog.xaml.cs
90 lines (83 loc) · 3.69 KB
/
PromptTimestampDialog.xaml.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
using System;
using System.Text.RegularExpressions;
using System.Windows;
namespace OverlayControl
{
/// <summary>
/// Window acting as a prompt for the user to enter a timestamp.
/// </summary>
public partial class PromptTimestampDialog : Window
{
public TimeSpan GivenTime { get => new TimeSpan(int.Parse(txtHours.Text), int.Parse(txtMinutes.Text), int.Parse(txtSeconds.Text)); }
/// <summary>
/// Constructor for the PromptTimestampDialog window, acting as a prompt for the user to enter a timestamp.
/// </summary>
public PromptTimestampDialog()
{
InitializeComponent();
}
#region Text Boxes
/// <summary>
/// Event fired when a text box that should only contain numbers is typed into.
/// </summary>
/// <param name="sender">The text box that fired this event.</param>
/// <param name="e">Contains state information and event data.</param>
private void txtNumber_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) =>
e.Handled = new Regex("[^0-9]+").IsMatch(e.Text);
/// <summary>
/// Event fired when a text box that should only contain numbers is pasted into.
/// </summary>
/// <param name="sender">The text box that fired this event.</param>
/// <param name="e">Contains state information and event data.</param>
private void txtNumber_Pasting(object sender, DataObjectPastingEventArgs e)
{
// Check if data is a string
if (e.DataObject.GetDataPresent(typeof(string)))
{
// Check if the data string only contains numbers; if not, cancel
if (new Regex("[^0-9]+").IsMatch((string)e.DataObject.GetData(typeof(string))))
e.CancelCommand();
}
// If data is not a string, cancel paste
else
e.CancelCommand();
}
/// <summary>
/// Event fired when a text box that should only contain numbers has data dragged down into it via mouse.
/// </summary>
/// <param name="sender">The text box that fired this event.</param>
/// <param name="e">Contains state information and event data.</param>
private void txtNumber_PreviewDragEnter(object sender, DragEventArgs e)
{
// Check if data is a string
if (e.Data.GetDataPresent(typeof(string)))
{
// Check if the data string only contains numbers; if not, cancel
e.Handled = new Regex("[^0-9]+").IsMatch((string)e.Data.GetData(typeof(string)));
}
// If data is not a string, cancel drag-down
else
e.Handled = true;
}
#endregion
/// <summary>
/// Event fired when button btnFinalize is clicked.
/// </summary>
/// <param name="sender">The button that was pressed to fire this event.</param>
/// <param name="e">Contains state information and event data.</param>
private void btnFinalize_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
/// <summary>
/// Event fired when the PromptTimestampDialog window is rendered.
/// </summary>
/// <param name="sender">The control that fired this event.</param>
/// <param name="e">Unused event arguments object.</param>
private void wndTimestampPrompt_ContentRendered(object sender, EventArgs e)
{
// Allow the user to type into the textbox immediately by putting it in focus when the window is rendered
txtHours.Focus();
}
}
}