帮编编一个倒计时程序。用C#,要求用户设定时间,以秒为单位,还要把倒计时剩余的秒数显示在tex
帮编编一个倒计时程序。用C#,要求用户设定时间,以秒为单位,还要把倒计时剩余的秒数显示在tex帮编一个倒计时程序。用C#,要求用户设定时间,以秒为单位,还要把倒计时剩余的...
帮编编一个倒计时程序。用C#,要求用户设定时间,以秒为单位,还要把倒计时剩余的秒数显示在tex帮编一个倒计时程序。用C#,要求用户设定时间,以秒为单位,还要把倒计时剩余的秒数显示在textbox里。(注:把需要的组件说清楚,如textbox,tomer,bottom等)。别从网上随便弄一段到这来。
展开
展开全部
int second; //存放秒
///<summary>
///tmrStart计时器控件,负责实现倒计时
///txtTimer是输入倒计时秒数的控件
///btnStart是控制程序开始的按钮
///btnClear是清除文本框txtTimer里面数字的按钮
///btnExit是退出整个程序的按钮
///lblTimer是文本框txtTimer左边的标签
///lblSecnd是文本框txtTimer右边边的标签
/// </summary>
public Form1()
{
InitializeComponent();
}
private void tmrStart_Tick(object sender, EventArgs e)
{
second = int.Parse(this.txtTimer.Text);
second--;
this.txtTimer.Text = second.ToString();
if (second == 0)
{
this.tmrStart.Enabled = false;
this.btnClear.Enabled = true;
MessageBox.Show("时间到!");
}
}
private void btnStart_Click(object sender, EventArgs e)
{
if (this.txtTimer.Text == "")
{
MessageBox.Show("必须输入一个数!");
}
else if (int.Parse(this.txtTimer.Text) <= 0)
{
MessageBox.Show("必须输入一个大于0的数!");
this.txtTimer.Text = ""; //清空文本框的值
}
else
{
this.btnStart.Enabled = false;
this.txtTimer.Enabled = false;
this.tmrStart.Enabled = true;
}
}
private void btnClear_Click(object sender, EventArgs e)
{
this.txtTimer.Text = "";
this.btnStart.Enabled = true;
this.btnClear.Enabled = false;
this.txtTimer.Enabled = true;
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
///<summary>
///tmrStart计时器控件,负责实现倒计时
///txtTimer是输入倒计时秒数的控件
///btnStart是控制程序开始的按钮
///btnClear是清除文本框txtTimer里面数字的按钮
///btnExit是退出整个程序的按钮
///lblTimer是文本框txtTimer左边的标签
///lblSecnd是文本框txtTimer右边边的标签
/// </summary>
public Form1()
{
InitializeComponent();
}
private void tmrStart_Tick(object sender, EventArgs e)
{
second = int.Parse(this.txtTimer.Text);
second--;
this.txtTimer.Text = second.ToString();
if (second == 0)
{
this.tmrStart.Enabled = false;
this.btnClear.Enabled = true;
MessageBox.Show("时间到!");
}
}
private void btnStart_Click(object sender, EventArgs e)
{
if (this.txtTimer.Text == "")
{
MessageBox.Show("必须输入一个数!");
}
else if (int.Parse(this.txtTimer.Text) <= 0)
{
MessageBox.Show("必须输入一个大于0的数!");
this.txtTimer.Text = ""; //清空文本框的值
}
else
{
this.btnStart.Enabled = false;
this.txtTimer.Enabled = false;
this.tmrStart.Enabled = true;
}
}
private void btnClear_Click(object sender, EventArgs e)
{
this.txtTimer.Text = "";
this.btnStart.Enabled = true;
this.btnClear.Enabled = false;
this.txtTimer.Enabled = true;
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询