Skip to content

Instantly share code, notes, and snippets.

@eternaltung
Created April 24, 2013 13:23
Show Gist options
  • Save eternaltung/5452086 to your computer and use it in GitHub Desktop.
Save eternaltung/5452086 to your computer and use it in GitHub Desktop.
using System;
using System.Windows;
using System.Windows.Threading;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(1) };
int sec = 5;
public MainWindow()
{
InitializeComponent();
timer.Tick += timer_Tick;
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
if (sec > 0)
{
sec--;
timerText.Text = sec.ToString(); //timerText是介面上的一個TextBlock
}
else
timer.Stop();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment