码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-21 17:28:18      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

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

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

标签:

原文地址:http://blog.csdn.net/querystringcom/article/details/45893631

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