Csharp/C#教程:有没有办法在等待输入时有倒数计时器?分享


有没有办法在等待输入时有倒数计时器?

我正在尝试在计时器用完之前创建一个需要用户输入的简单游戏。

基本上,页面将加载一段时间,并等待用户说出正确的答案。 如果时间用完,游戏就结束了,但如果用户做对了,他就会继续讨论下一个问题。

(我已经完成了演讲部分,我只需要弄清楚计时器)

有一个简单的方法来实现这一目标吗?

//Add Using Statement using System.Windows.Threading; //Create Timer DispatcherTimer mytimer; //Setup Timer myTimer = new DispatcherTimer(); myTimer.Interval = System.TimeSpan.FromSeconds(10); myTimer.Tick += myTimer_Tick; // When you type the +=, this method skeleton should come up // automatically. But type this in if it doesn't. void myTimer_Tick(object sender, EventArgs e) { //This runs when ever the timer Goes Off (In this case every 10 sec) } //Run Timer myTimer.Start() //Stop Timer myTimer.Stop() 

这会解决你的问题吗?

上述就是C#学习教程:有没有办法在等待输入时有倒数计时器?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/961253.html

(0)
上一篇 2021年11月25日
下一篇 2021年11月25日

精彩推荐