基本信息
源码名称:C# 简单计时器(倒计时)
源码大小:0.05M
文件格式:.zip
开发语言:C#
更新时间:2019-05-22
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 1 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 尚海涵的计时器
{
    public partial class Form1 : Form
    {  
        //类字段变量说明
        private int _nowSecond = 0;
         private void textBox1_TextChanged(object sender, EventArgs e)
        {
            _nowSecond = Convert.ToInt32(textBox1.Text)*10;
        }
        public Form1()
        {
            InitializeComponent();
        }
       
        private void timer1_Tick(object sender, EventArgs e)
        {
            
            _nowSecond--;
            //把当前时间值转换
            int hour = _nowSecond/36000;
            int minute =(_nowSecond %36000)/600;
            double second = (_nowSecond % 36000) % 600/10.0;

            if(hour<=9)
                labelHour.Text="0" hour.ToString();
            else
                labelHour.Text=hour.ToString();
            if (minute <= 9)
                labelMinute.Text = "0"   minute.ToString();
            else
                labelMinute.Text = minute.ToString();

            if (second <= 9)
                labelSecond.Text = "0"   second.ToString();
            else
                labelSecond.Text = second.ToString();
            if (_nowSecond ==0)
            {    
                timer1.Enabled = false;
                timer2.Enabled = false;
                MessageBox.Show("倒计时结束!!!");
               

            }

        }

        private void buttonStart_Click(object sender, EventArgs e)
        {   
            timer1.Enabled = true;
            timer2.Enabled = true;
            buttonStart.Enabled = false;
            buttonStop.Enabled = true;
            buttonPause.Enabled = true;



        }

        private void buttonPause_Click(object sender, EventArgs e)
        {          
            if (timer1.Enabled == true)
            {
                buttonPause.Text = "继续";
                timer2.Enabled = false;
                timer1.Enabled = false;
                labelColon1.Visible = true;
                labelColon2.Visible = true;
            }
            else
            {
                buttonPause.Text = "暂停";
                timer2.Enabled = true;
                timer1.Enabled = true;
            
            }
        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            buttonStart.Enabled = true;
            buttonPause.Enabled = false;
            buttonStop.Enabled = false;
            buttonPause.Text = "暂停";
            timer2.Enabled = false;
            timer1.Enabled = false;
            labelColon1.Visible = true;
            labelColon2.Visible = true;
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            //让中间的冒号闪烁起来
            if (labelColon1.Visible == true)
            {
                labelColon1.Visible = false;
                labelColon2.Visible = false;

            }
            else
            {
                labelColon1.Visible = true;
                labelColon2.Visible = true;

            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            buttonStart.Enabled = true;
            buttonPause.Enabled = false;
            buttonStop.Enabled = false;

            buttonPause.Text = "暂停";
            labelColon1.Visible = true;
            labelColon2.Visible = true;


        }

        private void Form1_Move(object sender, EventArgs e)
        {
            //停靠屏幕左右边框
            int screenRight = Screen.PrimaryScreen.Bounds.Right;
            int formRight = this.Left   this.Size.Width;
            if (Math.Abs(screenRight - formRight) <= 100)
                this.Location = new System.Drawing.Point(screenRight - this.Size.Width,this.Top);
            if (Math.Abs(this.Left) <= 100)
                this.Location = new System.Drawing.Point(0, this.Top);

            int screenBottom= Screen.PrimaryScreen.Bounds.Bottom;
            int formBottom = this.Top   this.Size.Height;
            if (Math.Abs(screenBottom - formBottom) <= 60)
                this.Location = new System.Drawing.Point(this.Left,screenBottom-this.Size.Height);
            if (Math.Abs(this.Left) <= 100)
                this.Location = new System.Drawing.Point(this.Left,0);

                    



        }

        private void labelHour_Click(object sender, EventArgs e)
        {

        }

    }
}