C# Timer Demo
来源:互联网 发布:php exec 执行权限 编辑:程序博客网 时间:2024/05/05 15:24
By Prasad H.
This is an example of a timer in C#. It gives you an understand of time / clock and time conversion functionality.
Some Tips using Timer:
1.Timer_Event will fire only after the Timer.Start() method is called.
2.Interval property is used to set the interval between Timer_Event.
3.Timer can be stopped either by disabling the Timer or calling the Stop() method.
using System;
using System.Windows.Forms;
using System.Drawing;
class TimerDemo:Form
{
Timer Clock;
Label lbTime=new Label();
public TimerDemo()
{
Clock=new Timer();
Clock.Interval=1000;
Clock.Start();
Clock.Tick+=new EventHandler(Timer_Tick);
this.Controls.Add(lbTime);
lbTime.BackColor=Color.Black;
lbTime.ForeColor=Color.Red;
lbTime.Font=new Font("Times New Roman",15);
lbTime.Text=GetTime();
}
public string GetTime()
{
string TimeInString="";
int hour=DateTime.Now.Hour;
int min=DateTime.Now.Minute;
int sec=DateTime.Now.Second;
TimeInString=(hour < 10)?"0" + hour.ToString() :hour.ToString();
TimeInString+=":" + ((min<10)?"0" + min.ToString() :min.ToString());
TimeInString+=":" + ((sec<10)?"0" + sec.ToString() :sec.ToString());
return TimeInString;
}
public void Timer_Tick(object sender,EventArgs eArgs)
{
if(sender==Clock)
{
lbTime.Text=GetTime();
}
}
public static void Main()
{
Application.Run(new TimerDemo());
}
}
- C# Timer Demo
- (c# ) timer
- C# Timer
- C# Timer
- C# Timer
- timer demo 之一
- timer demo 之二
- Timer in C#
- 关于C#中的Timer
- C#中timer类
- C# Timer范例教程
- C#中timer类
- C# Timer类
- C#中的timer
- C#的Timer解析
- C#的Timer
- C#的Timer (转)
- C# Timer范例教程
- 架构师观点:将EJB组件公开为业务服务
- C#线程初步(转载)
- 合成模式构造treeview 改进版
- SOA代表了基于组件的应用程序发展
- J2ME开发入门(二) 一个简单的分页
- C# Timer Demo
- ASP.NET中上传并读取Excel文件数据
- iplanet
- 生活感言
- Linux文件系统
- DataList分页
- [Matlab GUI]handles的问题
- 工作流与BPEL的区别
- 信息抽取