C#倒计时不听话了...........

来源:百度知道 编辑:UC知道 时间:2024/07/02 17:24:32
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Timer
{
public partial class Form1 : Form
{
int index=60;
public Form1()
{
InitializeComponent();
}

private void btnAction_Click(object sender, EventArgs e)
{
this.timer1.Enabled = true;

this.btnAction.Text = "暂停计时";
}
private void timer1_Tick(object sender, EventArgs e)
{
this.txtTime.Text = index.ToString();
if (index <= 60)
{
index--;
}
else
{
index = 0;
}
}
<

index = 0; 你把它弄成0 第一次计时完成就罢工了

你的程序看不出来那错了...
public partial class Form1 : Form
{
Timer t1 = new Timer();
Button start = new Button();
Button end = new Button();
TextBox text1 = new TextBox();
long time = 0;
public Form1()
{
InitializeComponent();
t1.Interval = 1000;
this.Controls.Add(this.start);
this.Controls.Add(this.end);
this.Controls.Add(this.text1);
this.start.Text = "start";
this.end.Text = "end";
this.start.Location = new Point(0, 0);
this.end.Location = new Point(0, 50);
this.text1.Location = new Point(0, 100);
this.start.Click += new EventHandler(start_Click);
this.end.Click += new EventHandler(end_Click);
t1.Tick += new Event