All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Discuz!,X-Space下的二级域名配置_php资料_编程技术
Delphi带进度条的状态栏实例
当ASP.NET撞上JSF之校验输入方式的差异_[Asp.Net教程]
事半功倍之javascript(2)_JavaScript技术_编程技术
javascript事件列表_JavaScript技术_编程技术
delphi弹出选择对话框选择目录
编写数据库操作类,使ASP.NET中的数据库操作变得简单_[Asp.Net教程]
精通数据库系列之入门-技巧篇3_mssql学习_编程技术
迁移至64位SQL,Server,2005数据库_[SQL,Server教程]
C#中Label控件应用实例
Reading number is top 10 pictures
再来随便发几张
美丽的风景--让你目瞪口呆
西游日记2
HongMenYan premiere XinLiangGong clairvoyant outfit PK YiFeiLiu1
Sell the barbecue as says father du breul1
湖边的风景
Ashlynn Brooke photograph of a group3
狗狗与主人神同步2
影评-疯子,我爱你
29 the belle stars after bath figure3
Download software ranking
The cock of the Grosvenor LTD handsome
matrix3
Sora aoi, the maid, students' uniforms
jBuilder2006
虚拟机汉化软件
Tram sex maniac 2 (H) rar bag8
天龙八部十二宫服务端
Unix video tutorial19
C#程序员参考手册
Eclipse 4.2.2 For Win32
qq published in(发表于) 2014/7/11 9:18:14 Edit(编辑)
C#中Timer组件应用实例

C#中Timer组件应用实例

C#中Timer组件应用实例

Timer组件

1.功能

Timer是定期引发事件的组件,该组件是为Windows窗体环境设计的,图1所示为Timer组件。



图1 Timer组件

2.属性

(1)Enable属性。此属性用于指定计时器是否运行,此属性设置为True,则表示可以启动计时器。

语法:

public bool Enabled { get; set; }
属性值:如果Timer引发Elapsed事件,则为True;否则,为False。默认值为False。

(2)Interval属性。获取或设置引发Elapsed事件的间隔。

语法:

public double Interval { get; set; }
属性值:引发Elapsed事件的间隔时间(以ms为单位)。默认值为100ms。

示例

Enabled属性和Interval属性的使用

本示例设置Timer控件的间隔时间和停止控件。

程序主要代码如下:

this.timer1.Interval = 1000;

this.timer1.Enabled = False;

3.事件

Tick事件:该事件在当指定的计时器间隔已过去而且计时器处于启用状态时发生。

语法:

public event EventHandler Tick
完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _8_11

{

static class Program

{

///



/// 应用程序的主入口点。

///


[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new frmPictureBox());

}

}

}

★★★★★frmPictureBox窗体设计文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace _8_11

{

public partial class frmPictureBox : Form

{

public frmPictureBox()

{

InitializeComponent();

}

private void frmPictureBox_Load(object sender, EventArgs e)

{

this.pictureBox1.Image = imageList1.Images[0];

this.pictureBox2.Image = imageList1.Images[1];

this.pictureBox1.SizeMode= PictureBoxSizeMode.StretchImage;

this.timer1.Interval = 1000;

this.timer1.Enabled = false;

}

private void pictureBox1_Click(object sender, EventArgs e)

{

this.timer1.Enabled = true;

}

private void button2_Click(object sender, EventArgs e)

{

}

private void timer1_Tick(object sender, EventArgs e)

{

this.label2.Text = "现在时间为:" + DateTime.Now.ToString();

}

private void button1_Click(object sender, EventArgs e)

{

}

public int i = 0;

private void pictureBox2_Click(object sender, EventArgs e)

{

this.timer2.Enabled = true;

}

private void timer2_Tick_1(object sender, EventArgs e)

{

this.pictureBox2.Image = this.imageList1.Images[i];

i++;

if (i == imageList1.Images.Count - 1)

i = 0;

}

}

}

★★★★★frmPictureBox窗体代码文件完整程序代码★★★★★


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.