我写了个倒数计时器 如何动态生成?
先上代码: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;
using System.Threading;
using System.Timers;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
private TimeSpan ts= new TimeSpan();
public Form1()
{
InitializeComponent();
}
int a, b, c;
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
a = int.Parse(textBox2.Text);
b = int.Parse(textBox3.Text);
c = int.Parse(textBox4.Text);
ts = new TimeSpan(a,b,c);
}
private void timer1_Tick(object sender, EventArgs e)
{
string str = ts.Hours.ToString() + ":" + ts.Minutes.ToString() + ":" + ts.Seconds.ToString();
textBox1.Text = str;
ts=ts.Subtract(new TimeSpan(0,0,1));
if (ts.TotalSeconds < 0.0)
{
timer1.Enabled = false;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
代码中 我们有一个按钮 四个textbox 和一个timer控件 就是一个小的计时器
在前3个按钮输入时间 点 button1就能实现倒数计时,
但我想在一个界面弄几个这样的计时器,
我想在新建一个按钮控件 点一下 就可以新建一个计时器实现大量的不同对象的计时
高手帮帮忙