1 .system.windows.forms

 .system.threading.timer

 .system.timers.timer

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms; namespace winformTimer
{
public partial class Form1 : Form
{
//不精确
public System.Windows.Forms.Timer timerEve;
public Form1()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
} private void button1_Click(object sender, EventArgs e)
{
timerEve = new System.Windows.Forms.Timer();
timerEve.Interval = ;
timerEve.Tick += timerEve_Tick;
timerEve.Start();
} void timerEve_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
}
public System.Timers.Timer timeEveTwo;
private void button2_Click(object sender, EventArgs e)
{
//Thread thread = new Thread(new ParameterizedThreadStart(theout));
//thread.Start();
timeEveTwo = new System.Timers.Timer();
//到达时间,执行事件
timeEveTwo.Elapsed += new System.Timers.ElapsedEventHandler(theout);
//执行一次为false 一直执行为true
timeEveTwo.AutoReset = true;
timeEveTwo.Start(); }
public void theout(object source,System.Timers.ElapsedEventArgs e)
{
//if(label2.InvokeRequired)
//{
// Action<string> changetime = (s) => { label2.Text = s.ToString(); };
// label2.Invoke(changetime);
//}
//else
//{
label2.Text = DateTime.Now.ToString();
//}
}
//Callback:一个 TimerCallback 委托,表示要执行的方法。
//State:一个包含回调方法要使用的信息的对象,或者为空引用(Visual Basic 中为 Nothing)。
//dueTime:调用 callback 之前延迟的时间量(以毫秒为单位)。指定 Timeout.Infinite 以防止计时器开始计时。指定零 (0) 以立即启动计时器。
//Period:调用 callback 的时间间隔(以毫秒为单位)。指定 Timeout.Infinite 可以禁用定期终止。
public System.Threading.Timer threadtimer; private void button3_Click(object sender, EventArgs e)
{
threadtimer = new System.Threading.Timer(new TimerCallback(timecall),null,,);
}
private void timecall(object obj)
{
label3.Text = DateTime.Now.ToString();
}
}
}

三种timer控件的简单实例的更多相关文章

  1. 关于c#中的Timer控件的简单用法

    Timer控件主要会用到2个属性一个是Enabled和IntervalEnabled主要是控制当前Timer控件是否可用timer1.Enabled=false;不可用timer1.Enabled=t ...

  2. QT代理Delegates使用实例(三种代理控件)

    效果如下,在表格的单元格中插入控件,用Delegates方式实现 源代码如下: main.cpp文件 #include <QApplication>#include <QStanda ...

  3. 用Delphi实现文件下载的几种方法(三种使用控件的方法)

    有个API就是UrlDownloadToFile.不仅如此,Delphi的一些控件也可以轻松实现下载,如NMHTTP,指定NMHTTP1.InputFileMode := ture; 指定Body为本 ...

  4. ASP.NET AJAX入门系列(10):Timer控件简单使用

    本文主要通过一个简单示例,让Web页面在一定的时间间隔内局部刷新,来学习一下ASP.NET AJAX中的服务端Timer控件的简单使用. 主要内容 Timer控件的简单使用 1.添加新页面并切换到设计 ...

  5. Windows Phone中的几种集合控件

    前言 Windows Phone开发过程中不可避免的就是和集合数据打交道,如果之前做过WP App的开发的话,相信你已经看过了各种集合控件的使用.扩展和自定义.这些个内容在这篇博客里都没有,那么我们今 ...

  6. winform学习(11)Timer控件

    利用Timer控件制作简单的跑马灯: 拉一个Lable控件至窗体中心,Text内容为★▶◀★▶◀★▶◀★▶◀ 再拉一个Timer控件,属性Enabled设置为True(即开启控件),Interval设 ...

  7. Jquery如何序列化form表单数据为JSON对象 C# ADO.NET中设置Like模糊查询的参数 从客户端出现小于等于公式符号引发检测到有潜在危险的Request.Form 值 jquery调用iframe里面的方法 Js根据Ip地址自动判断是哪个城市 【我们一起写框架】MVVM的WPF框架(三)—数据控件 设计模式之简单工厂模式(C#语言描述)

    jquery提供的serialize方法能够实现. $("#searchForm").serialize();但是,观察输出的信息,发现serialize()方法做的是将表单中的数 ...

  8. 10、面向对象以及winform的简单运用(isMdicontainer的设置、timer控件进行倒计时的制作)

    IsMdicontainer的设置 这是对于整个窗体的设置,将一个窗体的IsMdicontainer设置为true之后,再打开新窗体便可以让新窗体被父容器包括在内. 操作方法: 1)先建立一个子窗体C ...

  9. C# Winfrom 简单的运用Timer控件

    注意,在使用DateAndTime时,需要添加引用 using Microsoft.VisualBasic;否则不可以计算时间之间的差值. using System; using System.Col ...

随机推荐

  1. bash&nbsp;shell笔记3&nbsp;结构化命令二

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://twentyfour.blog.51cto.com/945260/513601 三 ...

  2. 批量插入数据insert into select示例

    //增加 $addSql =" insert into hxqc_auth_group_limits(group_id,company_id)"; foreach ($add_da ...

  3. POJ1012(约瑟夫问题)

    1.题目链接地址 http://poj.org/problem?id=1012 2k个人,前面k个是好人,后面k个是坏人,找一个数t,每数到第t时就去掉,使所有坏人在好人之前被杀掉. 思路:约瑟夫公式 ...

  4. Entitlements

    [Entitlements] Entitlements confer specific capabilities or security permissions to your iOS or OS X ...

  5. jQuery 对象和 json 之间的转换

    JSON.parse() json 转换成 对象 JSON.stringify() 对象转换成json 想问下广大网友大神 js 里面有数组转换或者转换成数组的函数么?小弟等--

  6. SaeMysql操作示例

    新浪sae的官方说明文档:http://apidoc.sinaapp.com/sae/SaeMysql.html Class SaeMysql 具体实现:http://apidoc.sinaapp.c ...

  7. 解决0RA-04031故障

    1.客户反应报表数据很慢,简单查询5分钟都出不来. 2.登陆数据库服务器检查日志:Thu Mar 21 16:20:30 2013Errors in file /opt/oracle/diag/rdb ...

  8. PyGrub

    from:https://wiki.debian.org/PyGrub Using pyGRUB on Wheezy to boot a domU kernel Using pyGRUB from x ...

  9. 关于for循环的一个小问题

    有如下程序: package com.lk.B; public class Test5 { public static void main(String[] args) { // TODO Auto- ...

  10. Python倒序循环列表(序列)

    如果要倒序遍历访问序列中的元素,可以对该序列使用reversed() 函数,reversed函数会生成一份倒序列表的拷贝,但是不会改变原列表.这个函数理解起来很自然,例如 for i in rever ...