Created
April 24, 2013 13:23
-
-
Save eternaltung/5452086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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