timer控件 倒计时 顺时计时 重置计时

来源:互联网 发布:手机淘宝如何发送链接 编辑:程序博客网 时间:2024/05/08 20:38

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Remind{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_SizeChanged(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) //判断是否最小化 { this.ShowInTaskbar = false; //不显示在系统任务栏 notifyIcon1.Visible = true; //托盘图标可见 } } private void notifyIcon1_DoubleClick(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.ShowInTaskbar = true; //显示在系统任务栏 this.WindowState = FormWindowState.Normal; //还原窗体 notifyIcon1.Visible = false; //托盘图标隐藏 } } private int temptime = 0; // private int temptime2 = 0; private void button1_Click(object sender, EventArgs e) { //开始 timeStart(); } private void timeStart() { if (string.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("分钟数不能为空"); return; } if(timer1.Enabled) { MessageBox.Show("亲!计时已经开始了"); return; } temptime = int.Parse(textBox1.Text) * 60; timer1.Tick += new EventHandler(timer1_Tick); timer1.Interval = 1000; timer1.Enabled = true; timer1.Start(); } private void Form1_Load(object sender, EventArgs e) { TimeSpan st = new TimeSpan(0, 0, Convert.ToInt32( textBox1.Text)*60); TimeSpan st2 = new TimeSpan(0, 0, temptime2); //倒时 lbltime.Text = st.ToString(); //顺时 lbltime2.Text = st2.ToString(); } private void timer1_Tick(object sender, EventArgs e) { temptime = temptime - 1; temptime2 = temptime2 + 1; if(temptime<=0) { //如果最小化在系统托盘,倒时完成将弹出来 if (this.WindowState == FormWindowState.Minimized) { this.ShowInTaskbar = true; //显示在系统任务栏 this.WindowState = FormWindowState.Normal; //还原窗体 notifyIcon1.Visible = false; //托盘图标隐藏 timer1.Stop(); timer1.Enabled = false; timer1.Dispose(); } MessageBox.Show("亲!请重置刷新后再次开始计时"); this.Dispose(); System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); } TimeSpan st = new TimeSpan(0, 0, temptime); TimeSpan st2 = new TimeSpan(0, 0, temptime2); //倒时 lbltime.Text = st.ToString(); //顺时 lbltime2.Text = st2.ToString(); } private void button2_Click(object sender, EventArgs e) { //重置 this.Dispose(); System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); } private void textBox1_TextChanged(object sender, EventArgs e) { } }}



下载地址:http://download.csdn.net/detail/querystringcom/8724943

0 0
原创粉丝点击