用C#窗口编写计时器 ,我写的程序运行时是0:0:1这样升的,要是换成运行时00:00:01的升,该怎么改?
inth=0,m=0,s=0;privatevoidbtn1_Click(objectsender,EventArgse){timer1.Enabled=true;}pr...
int h = 0, m =0, s =0;
private void btn1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void btn2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
private void btn3_Click(object sender, EventArgs e)
{
h = 0; m = 0; s = 0;
textBox1.Text = "00:00:00";
}
private void timer1_Tick(object sender, EventArgs e)
{
s++;
if (s == 60)
{
s = 0;
m++;
if (m == 60)
{
m = 0;
h++;
}
}
textBox1.Text = h.ToString() + ":" + m.ToString() + ":" + s.ToString();
} 展开
private void btn1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void btn2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
private void btn3_Click(object sender, EventArgs e)
{
h = 0; m = 0; s = 0;
textBox1.Text = "00:00:00";
}
private void timer1_Tick(object sender, EventArgs e)
{
s++;
if (s == 60)
{
s = 0;
m++;
if (m == 60)
{
m = 0;
h++;
}
}
textBox1.Text = h.ToString() + ":" + m.ToString() + ":" + s.ToString();
} 展开
3个回答
展开全部
private void timer1_Tick(object sender, EventArgs e)
{
s++;
int hh, mm, ss;
hh = s / 3600;
mm = (s - hh * 3600) / 60;
ss = s % 60;
textBox1.Text = string.Format("{0:d2}:{1:d2}:{2:d2}", hh, mm, ss);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
// 根据你的程序改的
private void timer1_Tick(object sender, EventArgs e)
{
int h = 0, m = 0, s = 0;
s++;
if (s == 60)
{
s = 0;
m++;
if (m == 60)
{
m = 0;
h++;
}
}
string hou = h < 10 ? "0" + h.ToString() : h.ToString();
string min = m < 10 ? "0" + m.ToString() : m.ToString();
string soc = s < 10 ? "0" + s.ToString() : s.ToString();
//string str = hou + ":" + min + ":" + soc;
textBox1.Text = hou + ":" + min + ":" + soc;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
试试看这样行不?
h.ToString(“00”) + ":" + m.ToString(“00”) + ":" + s.ToString(“00”);
h.ToString(“00”) + ":" + m.ToString(“00”) + ":" + s.ToString(“00”);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询