小山子

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

006_My006App_电子表

 

先添加一个时钟控件, 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;  //显示时间
}

 

显示效果如下:

 

image

posted on 2010-10-25 08:28  小山子  阅读(338)  评论(0)    收藏  举报