告诉你个简单的方法:
举个例子 比如你想在一个 label控件中 显示时间
先把 timer控件拖入 你创建的form窗体中 然后在窗体中双击timer控件
进入 timer_Tick 在其中写入 :
DateTime dt = DateTime.Now;
label1.Text = dt.ToString("yyyy年M月d日 dddd hh:mm:ss");
显示时间格式为 2008年11月30日 星期日 18:06:12
OK!! 完成
LZ给分把~!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
System.Timers.Timer aTimer = new System.Timers.Timer();
//Timer.Enabled 属性用于设置是否启用定时器
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 5 seconds.
//Timer.Interval 属性,事件的间隔,单位毫秒
aTimer.Interval = 5000;
//Timer.Elapsed 事件,达到间隔时发生
aTimer.Enabled = true;
Console.WriteLine("Press \'q\' to quit the sample.");
while (Console.Read() != 'q') ;
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("自己领会吧!");
}
}
}
平时多看一下控件类型的技术文章吧。如: http://www.evget.com/zh-CN/Info/ 这些问题,唉~!