用C#写倒计时timer1怎么写(是用textBox1输入的时间) 5
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
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 f
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected static int hour = 0;
protected static int mm = 0;
protected static int ss = 0;
private void button1_Click(object sender, EventArgs e)
{
int result = 0;
if (int.TryParse(textBox1.Text, out result))
{
hour = Convert.ToInt32(textBox1.Text);
}
else
{
hour = result;
}
ToLable(hour);
if (int.TryParse(textBox2.Text, out result))
{
mm = Convert.ToInt32(textBox2.Text);
}
else
{
mm = result;
}
ToLable(mm);
if (int.TryParse(textBox3.Text, out result))
{
ss = Convert.ToInt32(textBox3.Text);
}
else
{
ss = result;
}
ToLable(ss);
}
protected void ToLable(int time)
{
label1.Text = Convert.ToString(hour);
label3.Text = Convert.ToString(mm);
label5.Text = Convert.ToString(ss);
}
private void timer1_Tick(object sender, EventArgs e)
{
}
}
} 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace f
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected static int hour = 0;
protected static int mm = 0;
protected static int ss = 0;
private void button1_Click(object sender, EventArgs e)
{
int result = 0;
if (int.TryParse(textBox1.Text, out result))
{
hour = Convert.ToInt32(textBox1.Text);
}
else
{
hour = result;
}
ToLable(hour);
if (int.TryParse(textBox2.Text, out result))
{
mm = Convert.ToInt32(textBox2.Text);
}
else
{
mm = result;
}
ToLable(mm);
if (int.TryParse(textBox3.Text, out result))
{
ss = Convert.ToInt32(textBox3.Text);
}
else
{
ss = result;
}
ToLable(ss);
}
protected void ToLable(int time)
{
label1.Text = Convert.ToString(hour);
label3.Text = Convert.ToString(mm);
label5.Text = Convert.ToString(ss);
}
private void timer1_Tick(object sender, EventArgs e)
{
}
}
} 展开
展开全部
private void timer1_Tick(object sender, EventArgs e)
{
if(textBox3.text != "00")
{
int currentSS = convert.toInt32(textBox3.text);
currentSS--;
this.textBox3.text = currentSS;
}
else
{
if(textBox2.text != "00")
{
int currentMM = convert.toInt32(textBox2.text);
currentMM--;
this.textBox2.text = currentMM;
}
else
{
if(textBox1.text != "00")
{
int currentHH = convert.toInt32(textBox1.text);
currentHH--;
this.textBox1.text = currentHH;
}
else
{
///时、分、秒均为00
this.timer1.enabled = false;
}
}
}
}
{
if(textBox3.text != "00")
{
int currentSS = convert.toInt32(textBox3.text);
currentSS--;
this.textBox3.text = currentSS;
}
else
{
if(textBox2.text != "00")
{
int currentMM = convert.toInt32(textBox2.text);
currentMM--;
this.textBox2.text = currentMM;
}
else
{
if(textBox1.text != "00")
{
int currentHH = convert.toInt32(textBox1.text);
currentHH--;
this.textBox1.text = currentHH;
}
else
{
///时、分、秒均为00
this.timer1.enabled = false;
}
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询