首先要在Winform 窗体上拖拽一个Timer 时间控件 和Laber 控件
public int totalSecond = 15;
public int tenthSecond = 00;
void time()
{
int minute = totalSecond / 60;
int second = totalSecond % 60;
string str = minute.ToString() + ":" + second.ToString() + ":" + tenthSecond.ToString();
label2.Text = str;
tenthSecond--;
if (tenthSecond == -1)
{
tenthSecond = 59;
totalSecond--;
if (totalSecond == -1)
{
totalSecond = 15;
timer_run.Enabled = true;
timer_run.Enabled = true;
//调用的方法
}
}
}
然后 自己随便定义一个类的名称 例如 TimerClass 在timer1_Tcik 下调用此方法 TimerClass 即可出现倒计时,倒计时的时间自己设定 修改 时间的 字段 totalSecond tenthSecond 即可