我正在开发 Windows Phone 8 游戏应用程序。
我需要将倒计时功能添加到我的应用程序中。
就像应用程序启动时一样。定时器值显示 60,59,58....0
当 0 到达时显示消息“超时”。
我在谷歌搜索但我不知道。
[可能是我没有以正确的方式搜索的错误]
我尝试使用以下代码显示日期和时钟值,例如 [3/12/2014 6:22:10 PM]
C# Code
public SensorTwo()
{
InitializeComponent();
DispatcherTimer newTimer = new DispatcherTimer();
newTimer.Interval = TimeSpan.FromSeconds(1);
newTimer.Tick += OnTimerTick;
newTimer.Start();
}
void OnTimerTick(Object sender, EventArgs args)
{
clock.Text = DateTime.Now.ToString();
}
XAML代码
<TextBlock Foreground="Red" FontSize="22" Name="clock" Width="350" Height="50" HorizontalAlignment="Center" VerticalAlignment="Bottom"></TextBlock>
任何人帮助或指导我完成此功能......
//make global declaration of a counter variable
int counter =60;
void OnTimerTick(Object sender, EventArgs args)
{
counter --;
if(counter<0)
{
newTimer.Stop();
counter=60;
}
else
{
clock.Text =counter.ToString();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)