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

代码记录生活-倒计时

时间:2015-01-23 09:27:04      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

技术分享技术分享

我不会表达我的内心世界,那么我就用代码来记录我的生活,用一行行代码来表达我的心情。


虽然我写的代码都很简单,毕竟我是初学者,以后会慢慢的好的。


那么今天就先上传我昨天写的一个小计时器吧,就只有一个计时器功能,其他的没有。

源码分享地址链接:http://pan.baidu.com/s/1eQcT0A2 密码:4xru

1
using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.Media; 10 11 namespace 倒计时小工具 { 12 public partial class Form1 : Form { 13 int h, m, s, times; 14 Boolean a = true; 15 public Form1() { 16 InitializeComponent(); 17 } 18 public int gettime() { 19 h = Convert.ToInt32 ( numericUpDown1.Value ); 20 m = Convert.ToInt32 ( numericUpDown2.Value ); 21 s = Convert.ToInt32 ( numericUpDown3 .Value ); 22 return h * 3600 + m * 60 + s; 23 } 24 private void button1_Click ( object sender, EventArgs e ) { 25 times = gettime(); 26 progressBar1.Maximum = times; 27 progressBar1.Value = 0; 28 button3.Text = "暂停"; 29 a = true; 30 button3.Visible = true; 31 timer1.Start(); 32 label1.Text = "你设置的倒计时剩余:" + h + "小时" + m + "分钟" + s + ""; 33 } 34 35 private void button3_Click ( object sender, EventArgs e ) { 36 if ( a == true ) { 37 timer1.Stop(); 38 a = false; 39 button3.Text = "继续"; 40 } else { 41 timer1.Start(); 42 a = true; 43 button3.Text = "暂停"; 44 } 45 } 46 private void button2_Click ( object sender, EventArgs e ) { 47 timer1.Stop(); 48 progressBar1.Value = 0; 49 a = true; 50 button3.Text = "暂停"; 51 label1.Text = "请输入时间并开始"; 52 button3.Visible = false; 53 } 54 private void timer1_Tick ( object sender, EventArgs e ) { 55 if ( progressBar1.Value < times ) { 56 progressBar1.Value++; 57 time_1(); 58 label1.Text = "你设置的倒计时剩余:" + h + "小时" + m + "分钟" + s + ""; 59 } else { 60 timer1.Stop(); 61 button3.Visible = false; 62 SystemSounds.Exclamation.Play(); 63 MessageBox.Show ( "时间到了", "提示" ); 64 } 65 } 66 public void time_1() { 67 h = ( times-progressBar1.Value ) / 3600; 68 m = ( times - progressBar1.Value ) % 3600 / 60; 69 s = ( times - progressBar1.Value ) % 3600 % 60; 70 } 71 72 73 } 74 }

 

代码记录生活-倒计时

标签:

原文地址:http://www.cnblogs.com/nizidream/p/diary_0001.html

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