-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.xaml.cs
49 lines (41 loc) · 1.28 KB
/
Timer.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
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
namespace Gatta_Time
{
public partial class Timer : Page
{
public Timer()
{
InitializeComponent();
}
DispatcherTimer _timer;
TimeSpan _time;
void change()
{
TimeSpan ts = TimeSpan.FromSeconds(10);
ts = ts.Subtract(TimeSpan.FromSeconds(1));
Demso.Text = ts.ToString(@"hh\:mm\:ss");
}
public Timer(int hours, int minutes)
{
hours /= 10;
minutes /= 10;
InitializeComponent();
Console.WriteLine(Application.Current);
_time = TimeSpan.FromSeconds(hours * 3600 + minutes * 60);
_timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
{
Demso.Text = _time.ToString("c");
if (_time == TimeSpan.Zero) { Time_over(); _timer.Stop(); }
_time = _time.Add(TimeSpan.FromSeconds(-1));
}, Application.Current.Dispatcher);
_timer.Start();
}
public void Time_over()
{
this.NavigationService.Navigate(new Uri("End.xaml", UriKind.Relative));
}
}
}