欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c#編寫的番茄鐘倒計(jì)時(shí)器代碼

 更新時(shí)間:2015年03月17日 14:52:51   投稿:hebedich  
番茄鐘是老外做飯用的一個(gè)廚具,比如蒸包子,水開后再蒸十分鐘,就把番茄鐘擰一下擰到10的刻度上,然后番茄鐘就嗒嗒嗒的慢慢歸位,等到十分鐘后完全歸位,然后就叮的響一聲,提醒老外把火關(guān)掉。

恩  主要大家可以看下思路吧  圖形界面里 除了圖標(biāo)和音樂兩個(gè)資源 別的都是代碼。 時(shí)間沒有用timer組件 是自創(chuàng)的Time類在一個(gè)線程中進(jìn)行的倒計(jì)時(shí)。  對(duì)于導(dǎo)出記錄 創(chuàng)建了一個(gè)Record類  別的就沒什么了  。。。。

Program.cs

復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace 番茄鐘
{
    static class Program
    {
        /// <summary>
        /// 應(yīng)用程序的主入口點(diǎn)。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Form1.Designer.cs

復(fù)制代碼 代碼如下:

namespace 番茄鐘
{
    partial class Form1
    {
        /// <summary>
        /// 必需的設(shè)計(jì)器變量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;
        /// <summary>
        /// 清理所有正在使用的資源。
        /// </summary>
        /// <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
        #region Windows 窗體設(shè)計(jì)器生成的代碼
        /// <summary>
        /// 設(shè)計(jì)器支持所需的方法 - 不要
        /// 使用代碼編輯器修改此方法的內(nèi)容。
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.button4 = new System.Windows.Forms.Button();
            this.button5 = new System.Windows.Forms.Button();
            this.button6 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // label1
            //
            this.label1.BackColor = System.Drawing.Color.Black;
            this.label1.Font = new System.Drawing.Font("黑體", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.label1.ForeColor = System.Drawing.Color.Red;
            this.label1.Location = new System.Drawing.Point(12, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(283, 70);
            this.label1.TabIndex = 0;
            this.label1.Text = "倒計(jì)時(shí)  00:00";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(12, 104);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(65, 12);
            this.label2.TabIndex = 1;
            this.label2.Text = "番茄時(shí)間:";
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(83, 101);
            this.textBox1.MaxLength = 5;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(54, 21);
            this.textBox1.TabIndex = 2;
            this.textBox1.Text = "25";
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(12, 136);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(65, 12);
            this.label3.TabIndex = 5;
            this.label3.Text = "工作安排:";
            //
            // textBox2
            //
            this.textBox2.Location = new System.Drawing.Point(85, 133);
            this.textBox2.MaxLength = 300;
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(198, 21);
            this.textBox2.TabIndex = 6;
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(13, 163);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 7;
            this.button1.Text = "開始";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // button2
            //
            this.button2.Location = new System.Drawing.Point(108, 163);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 8;
            this.button2.Text = "停止";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            //
            // button3
            //
            this.button3.Location = new System.Drawing.Point(208, 162);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(75, 23);
            this.button3.TabIndex = 9;
            this.button3.Text = "暫停";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            //
            // richTextBox1
            //
            this.richTextBox1.BackColor = System.Drawing.Color.White;
            this.richTextBox1.ForeColor = System.Drawing.Color.Black;
            this.richTextBox1.Location = new System.Drawing.Point(13, 193);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.ReadOnly = true;
            this.richTextBox1.Size = new System.Drawing.Size(270, 279);
            this.richTextBox1.TabIndex = 10;
            this.richTextBox1.Text = "";
            //
            // label4
            //
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(144, 104);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(29, 12);
            this.label4.TabIndex = 11;
            this.label4.Text = "分鐘";
            //
            // button4
            //
            this.button4.Location = new System.Drawing.Point(13, 479);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(75, 23);
            this.button4.TabIndex = 12;
            this.button4.Text = "清空";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += new System.EventHandler(this.button4_Click);
            //
            // button5
            //
            this.button5.Location = new System.Drawing.Point(208, 478);
            this.button5.Name = "button5";
            this.button5.Size = new System.Drawing.Size(75, 23);
            this.button5.TabIndex = 13;
            this.button5.Text = "導(dǎo)出";
            this.button5.UseVisualStyleBackColor = true;
            this.button5.Click += new System.EventHandler(this.button5_Click);
            //
            // button6
            //
            this.button6.Font = new System.Drawing.Font("微軟雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.button6.Location = new System.Drawing.Point(191, 93);
            this.button6.Name = "button6";
            this.button6.Size = new System.Drawing.Size(104, 34);
            this.button6.TabIndex = 14;
            this.button6.Text = "番茄鐘 V1.1";
            this.button6.UseVisualStyleBackColor = true;
            this.button6.Click += new System.EventHandler(this.button6_Click_1);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(309, 508);
            this.Controls.Add(this.button6);
            this.Controls.Add(this.button5);
            this.Controls.Add(this.button4);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.richTextBox1);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "番茄鐘";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();
        }
        #endregion
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.RichTextBox richTextBox1;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Button button4;
        private System.Windows.Forms.Button button5;
        private System.Windows.Forms.Button button6;
    }
}

Form1.cs

復(fù)制代碼 代碼如下:

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;
using System.Threading;
using System.Collections;
using System.IO;
using System.Media;
using System.Reflection;
namespace 番茄鐘
{
    public partial class Form1 : Form
    {
        private Time time;
        private Thread cutDownThread;
        private bool pause=false;
        private int num = 0;
        private ArrayList records;
        string title = "倒計(jì)時(shí)  ";
        public void cutDownTime()
        {
            while (!time.Stop)
            {
                Thread.Sleep(1000);
                time.subOneSecond();
                this.Invoke((EventHandler)delegate
                {
                    label1.Text = title + time.showTime();
                });
            }
            this.Invoke((EventHandler)delegate
            {
                richTextBox1.AppendText("完成\n");
                Record r = (Record)records[records.Count - 1];
                r.getEnd("完成狀態(tài):完成");
            });
            Assembly asm = Assembly.GetExecutingAssembly();
            string name = asm.GetName().Name;
            SoundPlayer sp = new SoundPlayer(番茄鐘.Properties.Resources._3462_clip);
            sp.Play();
            MessageBox.Show("時(shí)間到了?。?!");
        }
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            richTextBox1.AppendText("已完成的番茄鐘記錄:\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 (!double.TryParse(textBox1.Text, out min))
                {
                    MessageBox.Show("請(qǐng)正確輸入數(shù)字");
                    return;
                }
                if (min < 0&&min>99)
                {
                    MessageBox.Show("請(qǐng)輸入一個(gè)不超過99的正實(shí)數(shù)");
                    return;
                }
                time = new Time(min);
                label1.Text = title + time.showTime();
                cutDownThread = new Thread(new ThreadStart(cutDownTime));
                cutDownThread.Start();
                StringBuilder temp = new StringBuilder();
                temp.Append("番茄鐘").Append(++num).Append(":");
                if (textBox2.Text != "")
                    temp.Append(textBox2.Text);
                else
                    temp.Append("無具體安排");
                records.Add(new Record(temp.ToString(), min));
                temp.Append("\n完成狀態(tài):");
                richTextBox1.AppendText(temp.ToString());
            }
            else
            {
                pause = 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 + time.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)records[records.Count - 1];
            r.getEnd("完成狀態(tài):未完成");
        }
        private void button4_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("你真的要清空嗎?\n(清空記錄會(huì)把之前所有\(zhòng)n  完成的番茄鐘記錄消\n  除,建議先將記錄導(dǎo)出)",
                "確認(rèn)",MessageBoxButtons.YesNo);
            if (dr == DialogResult.No)
            {
                MessageBox.Show("清空操作已撤銷");
            }
            else if (dr == DialogResult.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(object 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 sw = new StreamWriter(fs, Encoding.Default);
                sw.WriteLine("************************************************");
                sw.WriteLine("         " + DateTime.Now + "的番茄鐘記錄  ");
                sw.WriteLine("************************************************");
                foreach (Record r in records)
                {
                    sw.Write(r.showRecord());
                }
                sw.Close();
                fs.Close();
            }
        }
        private void button6_Click(object sender, EventArgs e)
        {
            double min = double.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.1\n 在使用中如遇到問題或發(fā)現(xiàn)漏洞,\n  請(qǐng)聯(lián)系QQ:583490567,謝謝!\n  本產(chǎn)品由曉奇工作室榮譽(yù)出品\n 版權(quán):Copyright © 蔣曉奇 2015",
                "關(guān)于番茄鐘", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
    public class Time
    {
        private 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;
            }
            else
                stop = true;
        }
        public bool Stop
        {
            get { return stop; }
        }
        public string showTime()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(min<10?"0"+min:min.ToString()).Append(":").Append(sec<10?"0"+sec:sec.ToString());
            return sb.ToString();
        }
    }
    public class Record
    {
        private string text;
        private DateTime first;
        private DateTime last;
        private double length;
        private string state;
        public Record(string text,double length)
        {
            this.text = text;
            first = DateTime.Now;
            this.length = length;
        }
        public void getEnd(string state)
        {
            last = DateTime.Now;
            this.state = state;
        }
        public string showRecord()
        {
            if (last == null)
                last = DateTime.Now;
            if (state == null)
                state = "未知";
            StringBuilder s = new StringBuilder();
            s.Append("起止時(shí)間:").Append(first.ToString()).Append("-").AppendLine(last.ToString());
            s.AppendLine(text).Append(state).Append("\t").
                Append("番茄鐘時(shí)長(zhǎng):").Append(length.ToString()).AppendLine("分鐘");
            return s.ToString();
        }
    }
}

以上就是本文分享的全部代碼了,希望大家能夠喜歡。

相關(guān)文章

  • Unity游戲開發(fā)之射擊小游戲的實(shí)現(xiàn)

    Unity游戲開發(fā)之射擊小游戲的實(shí)現(xiàn)

    本篇文章為大家?guī)硪粋€(gè)橫版2D射擊小游戲,游戲制作超級(jí)簡(jiǎn)單,玩法一學(xué)就會(huì)。文中的示例代碼講解詳細(xì),快跟隨小編一起動(dòng)手試一試
    2022-03-03
  • 淺談c#.net中巧用ToString()將日期轉(zhuǎn)成想要的格式

    淺談c#.net中巧用ToString()將日期轉(zhuǎn)成想要的格式

    有時(shí)候我們要對(duì)時(shí)間進(jìn)行轉(zhuǎn)換,達(dá)到不同的顯示效果,更多的該怎么辦呢?
    2013-03-03
  • C# 10個(gè)常用特性匯總

    C# 10個(gè)常用特性匯總

    這篇文章主要介紹了C# 10個(gè)常用特性,文中示例代碼非常詳細(xì),幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • Unity3D快速入門教程

    Unity3D快速入門教程

    本文講述了Unity3D如何快速入門,包含Unity3D游戲引擎介紹,學(xué)習(xí)歷程和Unity3D快速入門的途徑,通過該篇文章的講解,希望能夠讓你更好的去學(xué)習(xí)Unity3D引擎
    2021-06-06
  • C#中圖片旋轉(zhuǎn)和翻轉(zhuǎn)(RotateFlipType)用法分析

    C#中圖片旋轉(zhuǎn)和翻轉(zhuǎn)(RotateFlipType)用法分析

    這篇文章主要介紹了C#中圖片旋轉(zhuǎn)和翻轉(zhuǎn)(RotateFlipType)用法,實(shí)例分析了C#圖片旋轉(zhuǎn)及翻轉(zhuǎn)Image.RotateFlip方法屬性的常用設(shè)置技巧,需要的朋友可以參考下
    2015-06-06
  • C#/VB.NET實(shí)現(xiàn)在Word中插入或刪除腳注

    C#/VB.NET實(shí)現(xiàn)在Word中插入或刪除腳注

    腳注,是可以附在文章頁(yè)面的最底端的,對(duì)某些東西加以說明,印在書頁(yè)下端的注文。這篇文章將為您展示如何通過C#/VB.NET代碼,以編程方式在Word中插入或刪除腳注,需要的可以參考一下
    2023-03-03
  • C#開啟線程的四種示例

    C#開啟線程的四種示例

    這篇文章主要介紹了C#開啟線程的四種方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-10-10
  • C#中的擴(kuò)展方法詳解

    C#中的擴(kuò)展方法詳解

    “擴(kuò)展方法使您能夠向現(xiàn)有類型“添加”方法,而無需創(chuàng)建新的派生類型、重新編譯或以其他方式修改原始類型?!边@是msdn上說的,也就是你可以對(duì)String,Int,DataRow,DataTable等這些類型的基礎(chǔ)上增加一個(gè)或多個(gè)方法,使用時(shí)不需要去修改或編譯類型本身的代碼。
    2014-09-09
  • C#中的char與string詳解

    C#中的char與string詳解

    本文詳細(xì)講解了C#中的char與string,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-01-01
  • C#調(diào)用halcon實(shí)現(xiàn)使用鼠標(biāo)滾輪對(duì)圖片進(jìn)行縮放顯示

    C#調(diào)用halcon實(shí)現(xiàn)使用鼠標(biāo)滾輪對(duì)圖片進(jìn)行縮放顯示

    這篇文章主要為大家詳細(xì)介紹了C#如何調(diào)用halcon實(shí)現(xiàn)使用鼠標(biāo)滾輪對(duì)圖片進(jìn)行縮放顯示,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-03-03

最新評(píng)論