C# Winform Timer倒计时问题 只能用一次
可以根据输入的值来控制倒计时的事件。
假设输入的是180s
第一次点开始按钮是 180 179 178 ......正常的
点了重置按钮之后,第二次点开始按钮就是 180 178 176.....
再次重置并且点击开始按钮之后,变成 180 177 174...
...
这些间隔都是1s
这是什么情况?如何解决?
以下为简化版的代码:
private void buttonSetTimeStart_Click(object sender, EventArgs e)
{
this.Clock = 180;
this.timerSetTime.Enabled = true;
this.timerSetTime.Tick += new EventHandler(timerSetTime_Tick);
this.timerSetTime.Start();
}
void timerSetTime_Tick(object sender, EventArgs e)
{
Clock--;
this.labelSetTimeMinute.Text = Clock.ToString();
if (Clock == 0)
{
this.timerSetTime.Stop();
}
}
private void buttonSetTimeReset_Click(object sender, EventArgs e)
{
this.timerSetTime.Enabled = false;
this.timerSetTime.Stop();
this.timerSetTime.Interval = 1000;
this.labelSetTimeMinute.Text = "";
}
相关推荐
Winform倒计时器
使用C#代码编写的Winform倒计时器
Winform倒计时器实现指南
Winform,全称Windows Forms,是.NET框架中的一个用于构建丰富的客户端Windows应用程序的库。它为开发者提供了丰富的UI元素,如按钮、文本框、下拉列表等,使得创建交互式桌面应用程序变得简单而直观。Winform应用程序基于事件驱动模型,这意味着应用程序的执行流程主要由用户操作触发的事件来驱动。Winform最大的优势之一是它的控件重用性,开发者可以轻松创建自定义控件,并将它们集成到应用程序中。这一特性使得Winform能够满足从简单到复杂的各种应用程序需求。
C# WinForm-Timer控件的使用
比如在窗体中显示时间: 错误思路一:我在窗体结构函数中写入一个死循环,每隔一秒显示一次当前时间 public Form6() { InitializeComponent(); while (true) { label1.Text = DateTime.Now.ToString(yyyy年MM月dd日hh时mm分ss秒); System.Threading.Thread.Sleep(1000); } } 错误原因:结构函数无限循环,结构函数读不完代码是无法打开窗体的 错误思路二:放置一个按钮,
winform倒计时器
这是一个用C#做的简单倒计时器 对winform中的一些控件的简单应用
C# Timer的多线程使用方法
使用System.Threading.Timer 使用System.Timers.Timer 分别举例这两个类来实现多线程的时钟,不会阻塞UI线程 例子是Winform的


