using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace WindowsApplication1 { public partial class Form2 : Form { private int T = 3600; public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) {
请输入分钟数:
请输入秒数:如果小时为空,就显示00:xx:xx
如果分钟为空 就显示00:00:xx
string hour = "00";
string minute = "00";
string second = "00";Console.WriteLine("请输入小时数");
hour = Console.ReadLine();
Console.WriteLine("请输入分钟数");
minute = Console.ReadLine();
Console.WriteLine("请输入秒数");
second = Console.ReadLine();
Console.Write("{0}:{1}:{2}",hour,minute,second)
convert(varchar(10),yourtime,120)
Console.WriteLine("请输入小时数");
string hour = Console.ReadLine();
Console.WriteLine("请输入分钟数");
string minute = Console.ReadLine();
Console.WriteLine("请输入秒数");
string second = Console.ReadLine();
Console.Write("{0}:{1}:{2}", hour.Trim().Length == 0 ? "00" : hour, minute.Trim().Length == 0 ? "00" : minute, second.Trim().Length == 0 ? "00" : second);
button1.Text = aa.ToString(); //10:10:10;
long time=(long)timei;
DateTime dt = new DateTime(time);
dt.ToString();
button1.Text = aa.ToString("HH:mm:ss"); //10:10:10;
是个记时器 。。 timer控件
string minute = textBox2.Text.Trim();
string second =textBox3.Text.Trim();
if (hour == "")
hour = "00";
if (minute == "")
minute = "00";
if (second == "")
second = "00";
string str= hour + ":" + minute + ":" + second;不知道是不是你要的意思
当然textbox的值要判断的,是不是要符合的整数
string hour=textbox1.text.trim();
string min=textbox2.text.trim();
string sec=textbox3.text.trim();
if(string.isnullorempty(hour))
{
hour="00";
}
if(string.isnullorempty(min))
{
min="00";
}
if(string.isnullorempty(sec))
{
sec="00";
}label1.text=hour+":"+min+":"+sec;超简单,超笨的方法~~~~~~~~~~~~~~~~~~~~~~~~~
拖三个TextBox,一个Timer,一个Label,一个Button
三个TextBox的Text都设置为0;
Lable的Text设置为“尚未开始”
Timer的Interval设置为1000
Timer的Enable设置为False在Button的Click事件外面写上
private int T=0;Button的Click事件里面写上
int h=int.Parse(textBox1.Text);
int m=int.Parse(textBox2.Text);
int s=int.Parse(textBox3.Text);
T = h*60*60+m*60+s;
textBox1.Enable = false;
textBox2.Enable = false;
textBox3.Enable = false;
Timer1.Enable = true;
然后再 Timer的Ticks事件里面写上 T=T-1;
lable1.Text="倒计时 " + T.ToString()+" 秒";
if(t <=0 ){
textBox1.Enable = true;
textBox2.Enable = true;
textBox3.Enable = true;
Timer1.Enable = false;
lable1.Text="倒计时结束";
MessageBox.Show("倒计时结束!");
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form2 : Form
{
private int T = 3600;
public Form2()
{
InitializeComponent();
} private void Form2_Load(object sender, EventArgs e)
{
} private void timer1_Tick(object sender, EventArgs e)
{
timer1.Interval = 1000;
T--;
int h = T / (60 * 60);
int m = T / 60;
int s = T % 60;
label1.Text = string.Format("{0:00}:{1:00}",m,s);
} private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
}
}
现在啥也不说了.. .
格式化里的 {0:00}:{1:00}是什么意思.. - -!