码迷,mamicode.com
首页 > Windows程序 > 详细

C#自学之路27

时间:2015-04-13 21:08:50      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:public   程序   定时器   

定时器控件 

  定时器控件(timer),是按一定的时间间隔周期地自动触发事件。在程序运行时,定时器是不可见的。 1.常用的属性。a.Enable属性,为true就启动timer。b.InterVal属性,时间间隔,毫秒为单位。 2.常用的方法。a.Start和Stop方法,启动和停止定时器。 3.常用的事件。a.Tick事件。

  

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;


namespace WindowsFormsApplication12

{

    public partial class Form1 : Form

    {

        public bool bSave;


        public Form1()

        {

            InitializeComponent();

        }


        private void timer1_Tick(object sender, EventArgs e)

        {

            timer1.Enabled = false;

            if (bSave == false)

            {

                MessageBox.Show( "还没有保存!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information );

                bSave = true;

            }

            timer1.Enabled = true;

        }


        private void timer2_Tick(object sender, EventArgs e)

        {

            label1.Text = "当前时间:" + DateTime.Now;

        }


        private void Form1_Load(object sender, EventArgs e)

        {

            bSave = false;

            timer1.Enabled = true;

            timer2.Enabled = true;

        }


        private void textBox1_TextChanged(object sender, EventArgs e)

        {

            bSave = false;

        }

    }

}技术分享


本文出自 “郭俊的博客” 博客,转载请与作者联系!

C#自学之路27

标签:public   程序   定时器   

原文地址:http://10093949.blog.51cto.com/10083949/1631937

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!