计时器,设置interval时间间隔,每过一个interval事件.net给你一个时间到事件,+=这个事件的处理代码就好。.net给了两个计时器,一个是winform的,一个是system的,区别好像不大,不过是事件名称不一样。
解决方案 »
- c#主线程与子线程如何通信
- 一个新手问题,如何将获取了的textbox内容变成变量名再获取变量的值
- dategrid 动态添加的修改列,怎么激发修改事件???
- 如何判断图片是否损坏?
- 加分再问,如何对绑定数组的DataGrid列排序????
- 我想写一个创建数据库的语句在C#里怎么写?
- 动态绑定datagrid,刷新后页面之后不能显示该列。
- 反编译后的代码,怎么修改并保存到原来的dll中,我只修改了一个字符串的内容。
- 如何将dataset数据绑定到datagrid中
- 哪位告诉我排序后如何得到排序的数据呢?
- 拜求:(.NET C#)当我进行一个DundusChartPage的链接调用时,产生了一个错误,请问怎么解决??
- 哪里可以下载到管理系统的C#源码?(即winform的)
本示例以一秒为增量单位跟踪每天的时间。它使用窗体上的 Button、Label 和 Timer 组件。将 Interval 属性设置为 1000(等于一秒钟)。在 Timer 事件中,将标签的标题设置为当前时间。当单击按钮时,Enabled 属性将设置为 false,以使计时器停止更新标签标题。下面的代码假设您已有一个窗体,该窗体中有名为 Button1 的 Button 控件、名为 Timer1 的 Timer 控件以及名为 Label1 的 Label 控件。private void InitializeTimer()
{
//' Run this procedure in an appropriate event.
// Set to 1 second.
Timer1.Interval = 1000;
// Enable timer.
Timer1.Enabled = true;
Button1.Text = "Stop";
}private void Timer1_Tick(object Sender, EventArgs e)
{
// Set the caption to the current time.
Label1.Text = DateTime.Now.ToString();
}private void Button1_Click()
{
if ( Button1.Text == "Stop" )
{
Button1.Text = "Start";
Timer1.Enabled = false;
}
else
{
Button1.Text = "Stop";
Timer1.Enabled = true;
}
}
Timer1.Interval = 1000; //设定它1000ms(1s)动作(即Timer1_Tick)一次;
Timer1.Enabled = true; //运行时,它是激活的 ;
//要它隔Timer1.Interval = 1000 MS 做的动作
private void Timer1_Tick(object Sender, EventArgs e){ //Label1显示出的将是1s更新一次的数据,即电子表差不多的功能
Label1.Text = DateTime.Now.ToString();
}