[C#]006_My006App_电子表
时间:2010-10-25 来源:小山子
先添加一个时钟控件, Enable属性设置为Trun; Interval属性设置为1000
Code:
private void timer1_Tick(object sender, EventArgs e) //时钟控件
{
string timNewTime = "";
string timNewHour = Convert.ToString(DateTime.Now.Hour);
//定义“时”的值
if (Convert.ToInt32(timNewHour)<10) //值小于10的时候,在前面加0
{
timNewHour = "0" + timNewHour;
}
string timNewMinute = Convert.ToString(DateTime.Now.Minute);
if (Convert.ToInt32(timNewMinute) < 10) //值小于10的时候,在前面加0
{
timNewMinute = "0" + timNewMinute;
}
string timNewSecond = Convert.ToString(DateTime.Now.Second);
if (Convert.ToInt32(timNewSecond) < 10) //值小于10的时候,在前面加0
{
timNewSecond = "0" + timNewSecond;
}
timNewTime = timNewHour + ":" + timNewMinute + ":" + timNewSecond;
label1.Text = timNewTime; //显示时间
}
显示效果如下: