亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > C# > 正文

c#編寫的番茄鐘倒計時器代碼

2020-01-24 02:07:41
字體:
來源:轉載
供稿:網友

恩  主要大家可以看下思路吧  圖形界面里 除了圖標和音樂兩個資源 別的都是代碼。 時間沒有用timer組件 是自創的Time類在一個線程中進行的倒計時。  對于導出記錄 創建了一個Record類  別的就沒什么了  。。。。

Program.cs

復制代碼 代碼如下:

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

Form1.Designer.cs

復制代碼 代碼如下:

namespace 番茄鐘
{
    partial class Form1
    {
        /// <summary>
        /// 必需的設計器變量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;
        /// <summary>
        /// 清理所有正在使用的資源。
        /// </summary>
        /// <param name="disposing">如果應釋放托管資源,為 true;否則為 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
        #region Windows 窗體設計器生成的代碼
        /// <summary>
        /// 設計器支持所需的方法 - 不要
        /// 使用代碼編輯器修改此方法的內容。
        /// </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 = "倒計時  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 = "番茄時間:";
            //
            // 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 = "導出";
            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

復制代碼 代碼如下:

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 = "倒計時  ";
        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("完成狀態:完成");
            });
            Assembly asm = Assembly.GetExecutingAssembly();
            string name = asm.GetName().Name;
            SoundPlayer sp = new SoundPlayer(番茄鐘.Properties.Resources._3462_clip);
            sp.Play();
            MessageBox.Show("時間到了?。。?);
        }
        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("請正確輸入數字");
                    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();
                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完成狀態:");
                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("完成狀態:未完成");
        }
        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 == 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 在使用中如遇到問題或發現漏洞,/n  請聯系QQ:583490567,謝謝!/n  本產品由曉奇工作室榮譽出品/n 版權:Copyright © 蔣曉奇 2015",
                "關于番茄鐘", 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("起止時間:").Append(first.ToString()).Append("-").AppendLine(last.ToString());
            s.AppendLine(text).Append(state).Append("/t").
                Append("番茄鐘時長:").Append(length.ToString()).AppendLine("分鐘");
            return s.ToString();
        }
    }
}

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产精品99久久久久久白浆小说| 精品少妇v888av| 国产一区二区三区三区在线观看| 国产91精品最新在线播放| 色香阁99久久精品久久久| 在线观看亚洲视频| 国产精品视频男人的天堂| 欧美日韩美女视频| 亚洲女人天堂成人av在线| 国产精品观看在线亚洲人成网| 欧美精品激情blacked18| 久久免费精品日本久久中文字幕| 日韩电影中文字幕| 日韩中文在线视频| 亚洲精品久久久一区二区三区| 亚洲欧美第一页| 欧美日韩免费在线观看| 日韩欧美高清视频| 日韩精品在线观看一区| 欧美另类xxx| 久久久之久亚州精品露出| 日韩免费观看视频| 在线观看精品自拍私拍| 亚洲自拍偷拍网址| 久久久久久18| 91亚洲国产精品| 91视频国产高清| 国产日韩精品在线观看| 亚洲精品永久免费精品| 欧美国产一区二区三区| 国产欧美在线观看| 日韩精品999| 日韩高清欧美高清| 在线观看精品自拍私拍| 日韩高清a**址| 亚洲美女中文字幕| 亚洲黄色有码视频| 日韩激情视频在线播放| 欧美丰满老妇厨房牲生活| 亚洲免费一在线| 日韩av免费一区| 亚洲老头同性xxxxx| 中文字幕亚洲国产| 久久精品99久久久香蕉| 亚洲午夜性刺激影院| 激情亚洲一区二区三区四区| 欧美另类xxx| 亚洲日本中文字幕免费在线不卡| 亚洲人成五月天| 色综合视频网站| 国产热re99久久6国产精品| 一个人看的www欧美| 亚洲人a成www在线影院| 亚洲国产成人一区| 国内精品模特av私拍在线观看| 日韩高清av一区二区三区| 久久伊人精品一区二区三区| 国产成人精品最新| 国产欧美精品在线播放| 久久亚洲春色中文字幕| 91po在线观看91精品国产性色| 一区二区在线视频播放| 国产激情视频一区| 一区二区成人av| 欧美日韩aaaa| 中文字幕最新精品| 国产精品偷伦视频免费观看国产| 欧美性猛交xxxx乱大交3| 久久精品视频一| 日韩av在线一区二区| 一区三区二区视频| 欧美日韩国产成人在线| 欧美成人在线网站| 日韩av三级在线观看| 国产亚洲精品成人av久久ww| 成人黄色激情网| 国产一区视频在线播放| 国产精品自产拍在线观看| 亚洲午夜女主播在线直播| 91国产高清在线| 伊人久久大香线蕉av一区二区| 亚洲国产成人91精品| 狠狠做深爱婷婷久久综合一区| 欧美超级乱淫片喷水| 一本色道久久88精品综合| 亚洲精品视频免费在线观看| 亚洲人成电影网站色| 人人做人人澡人人爽欧美| 欧美大成色www永久网站婷| 亚洲成人av在线播放| 亚洲天堂av综合网| 日韩高清电影免费观看完整| 国产视频综合在线| 亚洲伊人久久大香线蕉av| 国产精品美女免费看| 欧美尤物巨大精品爽| 久久精品国产99国产精品澳门| 国产一区二区三区精品久久久| 欧美电影免费观看高清| 国产精品jizz在线观看麻豆| 亚洲男人天堂视频| 91精品久久久久久久久久| 欧美国产日韩二区| 91精品国产91久久久久久久久| 精品日本高清在线播放| 亚洲激情视频网站| 欧美性视频精品| 青青草国产精品一区二区| 亚洲精品女av网站| 欧美极品在线视频| 成人网中文字幕| 国产视频精品免费播放| 亚洲桃花岛网站| 亚洲第一网中文字幕| 国产精品久久久久久搜索| 欧美最猛性xxxxx亚洲精品| 久久精品电影网| 欧美成人免费va影院高清| 亚洲国产成人精品久久久国产成人一区| 高潮白浆女日韩av免费看| 亚洲第一级黄色片| 深夜精品寂寞黄网站在线观看| 日韩成人黄色av| 亚洲精品一区二区在线| 国产91色在线播放| 欧美裸体xxxx极品少妇| 欧美国产日韩视频| 国产精品亚洲片夜色在线| 91精品国产网站| 成人免费观看49www在线观看| 日韩在线高清视频| 亚洲国产一区二区三区四区| 欧美日韩在线免费观看| 午夜精品国产精品大乳美女| 亚洲成人网在线观看| 26uuu久久噜噜噜噜| 欧美成人免费va影院高清| 国产亚洲欧美日韩精品| 国产精品狼人色视频一区| 免费不卡欧美自拍视频| 亚洲最大福利视频网站| 日本精品免费一区二区三区| 国产一区二区日韩精品欧美精品| 国产精品福利在线观看| 久久久久久久色| 91伊人影院在线播放| 亚洲国产欧美一区二区三区久久| 欧美裸体视频网站| 亚洲欧美日韩在线一区| 欧美日韩在线免费| 丰满岳妇乱一区二区三区| 国产剧情久久久久久| 欧美色道久久88综合亚洲精品| 中文字幕亚洲无线码在线一区| 91精品国产乱码久久久久久蜜臀| 欧美精品一区二区三区国产精品| 最近免费中文字幕视频2019| 亚洲高清av在线| 久久成人在线视频| 欧美激情精品久久久久| 韩国精品久久久999| 欧美—级高清免费播放| 日韩一区二区三区xxxx| 国语自产精品视频在线看一大j8|