


版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、c#编写的番茄钟倒计时器代码番茄钟是老外做饭用的一个厨具, 比如蒸包子, 水开后再蒸十分钟, 就把番茄钟拧一下拧到10 的刻度上,然后番茄钟就嗒嗒嗒的慢慢归位,等到十分钟后完全归位,然后就叮的响一 声,提醒老外把火关掉。恩 主要大家可以看下思路吧 图形界面里 除了图标和音乐两个资源 别的都是代码。 时 间没有用 timer 组件 是自创的 Time 类在一个线程中进行的倒计时。 对于导出记录 创建 了一个 Record 类 别的就没什么了 。Program.cs复制代码 代码如下 :using System;using System.Linq;namespace 番茄钟static class
2、 Program/ <summary>/ 应用程序的主入口点。/ </summary>STAThreadstatic void Main()Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);Application.Run(new Form1();复制代码 代码如下 :namespace 番茄钟partial class Form1/ <summary>/ 必需的设计器变量。/ </summary>= null;/ <s
3、ummary>/ 清理所有正在使用的资源。/ </summary>/ <param name="disposing"> 如果应释放托管资源,为 true ;否则为 </param>protected override void Dispose(bool disposing)if (disposing && (components != null)components.Dispose();base.Dispose(disposing);#region Windows 窗体设计器生成的代码/ <summary>
4、;/ 设计器支持所需的方法 - 不要/ 使用代码编辑器修改此方法的内容。/ </summary>private void InitializeComponent()this.label1 = = = false 。newthis.label3 = = = = = = = = = this.button6 = this.SuspendLayout();/ label1/= 26.25F,= 黑 体 ",= = 9); = "label1"= 70); = 0;= "倒计时 00:00"= / label2/= true;= 104);
5、 = "label2"= 12); = 1;= "番茄时间: "/ textBox1/= 101); = 5; = "textBox1"= 21); = 2;= "25"/ label3/= true;= 136); = "label3"= 12); = 5;= "工作安排: "/ textBox2/= 133); = 300;= "textBox2"= 21);= 6;/ button1/= 163); = "button1"= 23
6、); = 7;= " 开始 "= true;+= new System.EventHandler(this.button1_Click); / button2/= 163); = "button2"= 23); = 8;= " 停止 "= true;+= new System.EventHandler(this.button2_Click); / button3/= 162); = "button3"= 23); = 9;= " 暂停 " = true;+= new System.EventHa
7、ndler(this.button3_Click); / richTextBox1/= = = 193); = "richTextBox1"= true;= 279); = 10;= ""/ label4/= true;= 104); = "label4"= 12); = 11;= "分钟 "/ button4/= 479); = "button4"= 23); = 12;= " 清空 " = true;+= new System.EventHandler(this.butt
8、on4_Click);/ button5/= 478); = "button5"= 23); = 13;= " 导出 " = true;+= new System.EventHandler(this.button5_Click);/ button6/12F,= 微 软 雅 黑 = 93); = "button6"= 34); = 14;= " 番茄钟 = += new System.EventHandler(this.button6_Click_1);/ Form1/this.AutoScaleDimensions = =
9、= 508); this.FormBorderStyle = = = false;this.Name = "Form1"this.StartPosition = = "番茄钟 "this.Load += new System.EventHandler(this.Form1_Load);this.ResumeLayout(false);this.PerformLayout();#endregionForm1.cs复制代码 代码如下 :using System;using System.ComponentModel;using System.Data;usi
10、ng System.Drawing;using System.Linq;using System.Text;using System.Threading;using System.Collections;using System.IO;using System.Media;using System.Reflection;namespace 番茄钟public partial class Form1 : Formprivate Time time;private Thread cutDownThread;private bool pause=false; private int num = 0;
11、private ArrayList records; string title = " 倒计时 " public void cutDownTime() while (!time.Stop)Thread.Sleep(1000); time.subOneSecond(); this.Invoke(EventHandler)delegate label1.Text = title + );this.Invoke(EventHandler)delegate richTextBox1.AppendText(" 完成 n"); Record r = (Record)
12、recordsrecords.Count - 1; r.getEnd(" 完成状态:完成 "););Assembly asm = Assembly.GetExecutingAssembly();string name = asm.GetName().Name;SoundPIayer sp = new SoundPIayer(番茄钟MessageBox.Show(”时间到了! ! !");public Form1()InitializeComponent();private void Form1_Load(object sender, EventArgs e)ric
13、hTextBox1.Appe ndText(” 已完成的番茄钟记录:n");records = new ArrayList();protected override void OnClosing(CancelEventArgs e)if (cutDownThread != null)if (cutDownThread.IsAlive) cutDownThread.Abort();base.OnClosing(e);private void button1_Click(object sender, EventArgs e)if (!pause)double min;if (!doubl
14、e.TryParse(textBox1.Text, out min)MessageBox.Show(”请正确输入数字”); return;if (min < 0&&min>99)MessageBox.Show(”请输入一个不超过 99的正实数"); return;time = new Time(min);label1.Text = title + time.showTime();cutDownThread = new Thread(new ThreadStart(cutDownTime);cutDownThread.Start();StringBuilde
15、r temp = new StringBuilder(); temp.Append(" 番茄钟 ").Append(+num).Append(":"); if (textBox2.Text != "")temp.Append(textBox2.Text);elsetemp.Append(" 无具体安排 "); records.Add( Record(temp.ToString(), min); temp.Append("n 完成状态: "); richTextBox1.AppendText(te
16、mp.ToString();elsepause = false;label1.Text = title + time.showTime();cutDownThread = new Thread(new ThreadStart(cutDownTime); cutDownThread.Start();private void button3_Click(object sender, EventArgs e)if (cutDownThread != null)if (cutDownThread.IsAlive)cutDownThread.Abort();label1.Text = title + t
17、ime.showTime();pause = true;private void button2_Click(object sender, EventArgs e)if (cutDownThread != null)if (cutDownThread.IsAlive)cutDownThread.Abort();time = new Time(0);label1.Text = title + time.showTime();richTextBox1.AppendText(" 未完成 n");Record r = (Record)recordsrecords.Count - 1
18、;r.getEnd(" 完成状态:未完成 ");private void button4_Click(object sender, EventArgs e)DialogResult dr = MessageBox.Show('你真的要清空吗? n (清空记录会把之前所有 n 完成的番茄钟记录消 n 除,建议先将记录导出) ","确认 ",MessageBoxButtons.YesNo);if (dr = DialogResult.No)MessageBox.Show('清空操作已撤销”);else if (dr = Dialog
19、Result.Yes)num = 0;richTextBox1.Text = "";richTextBox1.AppendText(" 已完成的番茄钟记录: n"); if (cutDownThread != null)if (cutDownThread.IsAlive)cutDownThread.Abort();time = new Time(0);label1.Text = title + time.showTime();MessageBox.Show("番茄钟记录已清空并重置!”);private void button5_Click(o
20、bject sender, EventArgs e)string fn="";OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = " 文本文件 (*.txt) |*.txt"; ofd.FilterIndex = 1; if (ofd.ShowDialog() = DialogResult.OK)fn = ofd.FileName;FileStream fs = new FileStream(fn, FileMode.Append, FileAccess.Write);StreamWriter
21、sw = new StreamWriter(fs, Encoding.Default); foreach (Record r in records) sw.WriteLine(11*”);sw.WriteLine("" + DateTime.Now + " 的番茄钟记录");sw.WriteLine(11*");sw.Write(r.showRecord();sw.Close(); fs.Close();private void button6_Click(object sender, EventArgs e)double min = doub
22、le.Parse(textBox2.Text);int a = (int)min;int b = (int)(min - a) * 60);textBox2.Text = a.ToString()+":"+b.ToString();private void button6_Click_1(object sender, EventArgs e) MessageBox.Show(" 番茄钟 V1.1n 在使用中如遇到问题或发现漏 洞,n 请联系QQ: 583490567 ,谢谢! n本产品由晓奇工作室荣誉出品n版权:Copyright? 蒋晓奇 2015",
23、"关于番茄钟 ", MessageBoxButtons.OK, MessageBoxIcon.Information); public class Timeprivate int sec;private int min; private bool stop;public Time(double min) this.min = (int)min;sec = (int)(min - this.min) * 60);stop = false;public void subOneSecond()if (sec > 0) sec-;else if (min > 0)min-; sec = 59;elsestop = true;public bool Stopget return stop; public string showTime()StringBuilder sb = new StringBuilder();sb.Append(min<10?"0"+min:min.ToString().Append("
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 车间职工管理方案模板
- 菜园农场改造方案
- 郑州幼教面试题及答案
- 南充日报面试题及答案
- 墓地整治工程方案
- 先锋团员面试题及答案
- 合作开发项目收益分配与知识产权保护协议
- 销售公司检查活动方案
- 西语财务面试题及答案
- 摩托机车考试题及答案
- 成人重症患者颅内压增高防控护理专家共识
- 2025年网络安全与信息保护基础知识考试题及答案
- 2025至2030中国家用血压计行业发展趋势分析与未来投资战略咨询研究报告
- 吉林省长春市2023−2024学年高二下册期末考试数学科试卷附解析
- 主管护师《相关专业知识》考试真题及答案(2025年)
- 绿化所仓库管理制度
- 聘请美容学徒合同协议
- 2025年全国保密教育线上培训考试试题库(含答案)含答案详解
- 2025年江苏省南京市鼓楼区中考一模英语试卷(含答案)
- 2023污泥协同处理厨余垃圾干式厌氧消化设备技术条件
- 机场旅客医疗救援应急预案
评论
0/150
提交评论