System.Windows.Forms.Timer
Windows 窗体 Timer 是定期引发事件的组件。该组件是为 Windows 窗体环境设计的。
时间间隔的长度由 Interval 属性定义,其值以毫秒为单位。若启用了该组件,则每个时间间隔引发一个 Tick 事件。
这是添加要执行的代码的位置。
Timer 组件的主要方法包括 Start 和Stop,这两种方法可打开和关闭计时器。计时器在关闭时重置;不存在暂停 Timer 组件的方法。
二、Windows 窗体 Timer 组件的 Interval 属性的限制
Windows 窗体 Timer 组件具有一个 Interval 属性,该属性指定一个计时器事件与下一个计时器事件之间间隔的毫秒数。
除非该组件被禁用,否则计时器会以大致相等的时间间隔继续接收 Tick 事件
Interval 属性:当编写 Timer 组件时,需要考虑 Interval 属性的几点限制:
如果应用程序或另一个应用程序对系统需求很大(如长循环、大量的计算或驱动程序、网络或端口访问),那么应用程序可能无法以 Interval 属性指定的频率来获取计时器事件。
间隔可以在 1 和 64,767 之间(包括 1 和 64,767),这意味着即使最长的间隔(大约 64.8 秒)也不会超过一分钟很多。
不能保证间隔所精确经过的时间。若要确保精确,计时器应根据需要检查系统时钟,而不是尝试在内部跟踪所积累的时间。
系统每秒生成 18 个时钟刻度,因此即使 Interval 属性以毫秒为单位,间隔的实际精度也不会超过十八分之一秒。
- System.Windows.Forms.Timer 类提供有关 Timer 类(用于 Windows 窗体计时器)及其成员的参考信息
private void InitializeTimer()
{
//' Run this procedure in an appropriate event.
// Set to 1 second.
Timer1.Interval = ;
// 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;
}
}
2、第二个代码示例每隔 600 毫秒运行一次过程,直到循环完成时为止。
下面的代码示例要求您拥有一个窗体,该窗体具有一个名为 Button1 的 Button 控件、一个名为 Timer1 的 Timer 控件和一个名为 Label1 的 Label 控件。
// This variable will be the loop counter.
private int counter; private void InitializeTimer()
{
// Run this procedure in an appropriate event.
counter = ;
timer1.Interval = ;
timer1.Enabled = true;
// Hook up timer's tick event handler.
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
} private void timer1_Tick(object sender, System.EventArgs e)
{
if (counter >= )
{
// Exit loop code.
timer1.Enabled = false;
counter = ;
}
else
{
// Run your procedure here.
// Increment counter.
counter = counter + ;
label1.Text = "Procedures Run: " + counter.ToString();
}
}
详细信息查看:http://msdn.microsoft.com/zh-cn/library/beza71x7(v=vs.80).aspx
System.Windows.Forms.Timer的更多相关文章
- System.Windows.Forms.Timer与System.Timers.Timer的区别(zz)
.NET Framework里面提供了三种Timer: System.Windows.Forms.Timer System.Timers.Timer System.Threading.Timer VS ...
- System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的 区别和用法
System.Windows.Forms.Timer执行的时候,如果你在过程中间加一个sleep整个的界面就死掉了,但是另外两个没有这个情况,System.Timers.Timer.System.Th ...
- 简述System.Windows.Forms.Timer 与System.Timers.Timer用法区别
System.Windows.Forms.Timer 基于窗体应用程序 阻塞同步 单线程 timer中处理时间较长则导致定时误差极大. System.Timers.Timer 基于服务 非阻塞异步 多 ...
- System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的差别和分别什么时候用
System.Windows.Forms.Timer.System.Timers.Timer.System.Threading.Timer的 区别和用法http://space.itpub.net/1 ...
- System.Windows.Forms.Timer反编译学习
using System; using System.ComponentModel; using System.Globalization; using System.Runtime; using S ...
- System.Windows.Forms.Timer的简单用法
Timer就是用来计时操作,如:你想在多少秒之后执行某个动作 Timer showTextBoxTimer = new Timer(); //新建一个Timer对象 showTextBoxTimer. ...
- System.Windows.Forms
File: winforms\Managed\System\WinForms\DataGridView.cs Project: ndp\fx\src\System.Windows.Forms.cspr ...
- .net chart(图表)控件的使用-System.Windows.Forms.DataVisualization.dll
这个案例指在介绍微软这套免费又功能强大的图表控件Microsoft Chart Controls for Microsoft .NET Framework 3.5,通过它,可让您的项目及报表,轻松套用 ...
- WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常
WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常 在wpf中封装Com组件时,调用组件 ...
随机推荐
- cocos2d-x 让精灵按照自己设定的运动轨迹行动
转自:http://blog.csdn.net/ufolr/article/details/7447773 在cocos2d中,系统提供了CCMove.CCJump.CCBezier(贝塞尔曲线)等让 ...
- UVa 11234 Expressions (二叉树重建&由叶往根的层次遍历)
画图出来后结果很明显 xyPzwIM abcABdefgCDEF sample output wzyxIPM gfCecbDdAaEBF * + - x y z w F B E a A d D b c ...
- SCOM2007R2安装和报表服务器配置
SCOM2007R2默认安装不可以直接支持SQL Server2008R2,需要SQL Server 2008SP1. 如果数据库安装在另一台计算机上,则在安装了SQL Server的计算机上先运行S ...
- 【转】The Zen of Python
http://www.python.org/dev/peps/pep-0020/ Beautiful is better than ugly. Explicit is better than impl ...
- Codeforces Round #330 (Div. 1) A. Warrior and Archer 贪心 数学
A. Warrior and Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594 ...
- phpcms v9和discuz X3.1实现同步登陆退出论坛(已实现)
网络上文章很多,按步骤配置好了之后phpcms可以同步登录dz,但是dz登录后状态却无法同步到phpcms,网络上找了很多资料都大同小异,头大.只能自己调试了,废话不多说了. 以下网络上抄 ...
- 线程池QueueUserWorkItem
// Test1.cpp : Defines the entry point for the console application. // #include "stdafx.h" ...
- Html&CSS 今日心得
今天和秋秋一起review了一下我自己写的登录页面.她给我提了几个point,对我很有启发. css样式的代码和html代码分离. 我自己做的时候是在google console里面调好了样式以后就直 ...
- Spring MVC 接收Json格式参数
今天做了一个关于表格排序的功能,可以通过右边的箭头做排序操作,每次操作需要通过Ajax将每条记录的Id数组作为参数去发送请求, 后台Spring MVC接到参数后作更改序号操作. 前端页面发送请求的代 ...
- c#智能感知(设置)及实现
1) 使用工具->选项菜单命令,选择文本编辑器->C#设置, 将上面圈出的2个复选框(自动列出成员和参数信息)打勾, 然后 Intellisense就会工作了.(如果没这么多选项,请勾选S ...