Windows Phone 8 用のストップウォッチを開発していますが、実際にはタイミングを正しく取得できません。1000ミリ秒ごとに秒を更新したいのですが、C#が初めてなので、正しく取得できません。これは私が今持っているコードです。:/
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Milli_Stopwatch;
using System.Windows.Threading;
namespace Milli_Stopwatch
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
DispatcherTimer timer = new DispatcherTimer();
int millisec = 00;
int sec = 00;
int min = 00;
int hour = 00;
Boolean check = false;
public MainPage()
{
InitializeComponent();
timer.Interval = new TimeSpan(0,0,0,0,1);
timer.Tick += new EventHandler(DispatcherTimer_tick);
}
private void DispatcherTimer_tick(object sender, EventArgs e)
{
if (millisec == 1000)
{
millisec = 00;
sec = sec + 1;
Secblock.Text = sec.ToString();
}
if (sec == 59)
{
sec = 00;
min = min + 1;
Minblock.Text = min.ToString();
}
if (min == 59)
{
min = 00;
hour = hour + 1;
Hourblock.Text = hour.ToString();
}
millisec = millisec + 1;
Millisecblock.Text = millisec.ToString();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (check == false)
{
timer.Start();
check = true;
startbutton.Content = "STOP";
}
else {
timer.Stop();
check = false;
startbutton.Content = "START";
}
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
timer.Stop();
check = false;
startbutton.Content = "START";
millisec = 000;
sec = 00;
min = 00;
hour = 00;
Millisecblock.Text = "00";
Secblock.Text = "00";
Minblock.Text = "00";
Hourblock.Text = "00";
}
}
}