This repository was archived by the owner on Jun 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
87 lines (74 loc) · 2.56 KB
/
MainWindow.xaml.cs
File metadata and controls
87 lines (74 loc) · 2.56 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
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using Hatter.Clock.Properties;
namespace Hatter.Clock
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private string _timeFormat;
private readonly DispatcherTimer _timer;
public MainWindow()
{
InitializeComponent();
if (!string.IsNullOrEmpty(Settings.Default.Left) && !string.IsNullOrEmpty(Settings.Default.Top))
{
double left, top;
if (double.TryParse(Settings.Default.Left, out left) && double.TryParse(Settings.Default.Top, out top))
{
Left = left;
Top = top;
}
}
ShowInTaskbar = false;
_timeFormat = Settings.Default.TimeFormat;
TimeFormatOption.Header = _timeFormat == "h:mm:ss tt" ? "24 Hour" : "12 Hour";
OnTimerTick(this, EventArgs.Empty);
_timer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Input, OnTimerTick, Dispatcher);
_timer.Start();
}
private void OnTimerTick(object sender, EventArgs e)
{
var now = DateTime.Now;
var clock = now.ToString(_timeFormat);
var date = now.ToString("ddd MMM dd, yyyy");
ClockInfo.Text = clock;
DateInfo.Text = date;
}
private void TimeFormatOption_OnClick(object sender, RoutedEventArgs e)
{
if (_timeFormat.Equals("h:mm:ss tt"))
{
TimeFormatOption.Header = "12 Hour";
_timeFormat = "H:mm:ss";
}
else
{
TimeFormatOption.Header = "24 Hour";
_timeFormat = "h:mm:ss tt";
}
Settings.Default.TimeFormat = _timeFormat;
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
_timer.Stop();
Settings.Default.Left = Left.ToString();
Settings.Default.Top = Top.ToString();
Settings.Default.Save();
base.OnClosing(e);
}
private void MenuItem_OnClick(object sender, RoutedEventArgs e)
{
Close();
}
private void MainWindow_OnMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
this.DragMove();
}
}
}