C # The Tomato Clock countdown timer code

Source: Internet
Author: User

Well, we can look at the idea. Graphical interface in addition to the icons and music two resources are the code.  Time is not used. The Timer component is the self-creating countdown of The Times class in a thread. Creating a record class for export records is nothing ....

Program.cs


The code is as follows:


? using System;

Using System.Collections.Generic;

Using System.Linq;

Using System.Windows.Forms;

namespace Tomato Bell

{

Static Class Program

{

<summary>

The main entry point for the application.

</summary>

[STAThread]

static void Main ()

{

Application.enablevisualstyles ();

Application.setcompatibletextrenderingdefault (FALSE);

Application.Run (New Form1 ());

}

}

}

Form1.Designer.cs


The code is as follows:


? namespace Tomato Clock

{

Partial class Form1

{

<summary>

The required designer variables.

</summary>

Private System.ComponentModel.IContainer components = null;

<summary>

Clean up all the resources that are in use.

</summary>

<param name= "disposing" > True if the managed resource should be disposed, otherwise false. </param>

protected override void Dispose (bool disposing)

{

if (disposing && (components = null))

{

Components. Dispose ();

}

Base. Dispose (disposing);

}

#region the code generated by the Windows Forms Designer

<summary>

The designer supports the required method – do not

Use the Code Editor to modify the contents of this method.

</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 ("Blackbody", 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 = "Countdown 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 = "Tomato Time:";

//

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 = "Work arrangement:";

//

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 = "Start";

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 = "Stop";

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 = "Pause";

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 = "Minutes";

//

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 = "Empty";

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 = "Export";

This.button5.UseVisualStyleBackColor = true;

This.button5.Click + = new System.EventHandler (This.button5_click);

//

Button6

//

This.button6.Font = new System.Drawing.Font ("Microsoft Jas Black", 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 = "Tomato Bell 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 = "Tomato Bell";

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


The code is as follows:


? 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 Tomato Bell

{

public partial class Form1:form

{

Private time time;

Private Thread Cutdownthread;

private bool Pause=false;

private int num = 0;

Private ArrayList Records;

string title = "Countdown";

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 ("complete \ n");

Record R = (record) records[records. COUNT–1];

R.getend ("Completion Status: Completed");

});

Assembly asm = assembly.getexecutingassembly ();

String name = asm. GetName (). Name;

SoundPlayer sp = new SoundPlayer (tomato bell). Properties.resources._3462_clip);

Sp. Play ();

MessageBox.Show ("Time is up!!!" ”);

}

Public Form1 ()

{

InitializeComponent ();

}

private void Form1_Load (object sender, EventArgs e)

{

Richtextbox1.appendtext ("Completed tomato clock record: \ 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 ("Please enter numbers correctly");

Return

}

if (min < 0&&min;>99)

{

MessageBox.Show ("Please enter a positive real number not exceeding 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 ("Tomato Bell"). Append (++num). Append (":");

if (TextBox2.Text! = "")

Temp. Append (TextBox2.Text);

Else

Temp. Append ("No specific arrangements");

Records. ADD (The new Record (temp. ToString (), Min));

Temp. Append ("\ n complete Status:");

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 ("not completed \ n");

Record R = (record) records[records. COUNT–1];

R.getend ("Completion status: Not Completed");

}

private void Button4_Click (object sender, EventArgs e)

{

DialogResult dr = MessageBox.Show ("Do you really want to empty it?") \ n (emptying the record will remove all previously completed tomato clock records, it is recommended to export the records first) ",

"Confirmation", Messageboxbuttons.yesno);

if (dr = = dialogresult.no)

{

MessageBox.Show ("Empty operation has been revoked");

}

else if (dr = = Dialogresult.yes)

{

num = 0;

richTextBox1.Text = "";

Richtextbox1.appendtext ("Completed tomato clock record: \ n");

if (cutdownthread! = null)

if (cutdownthread.isalive)

Cutdownthread.abort ();

Time = new Time (0);

Label1. Text = title + Time.showtime ();

MessageBox.Show ("Tomato clock record has been emptied and reset!") ”);

}

}

private void Button5_click (object sender, EventArgs e)

{

String Fn= "";

OpenFileDialog ofd = new OpenFileDialog ();

Ofd. Filter = "text file (*.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 +" of the Tomato Clock record ");

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 ("Tomato clock v1.1\n in use if you encounter problems or find loopholes, \ n Please contact qq:583490567, thank you!" \ n This product Yu Xiaochi Studio honors Copyright: Copyrights? Shang 2015″,

"About tomato Clock", 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 = "Unknown";

StringBuilder s = new StringBuilder ();

S.append ("Start/End Time:"). Append (first. ToString ()). Append ("-"). Appendline (last. ToString ());

S.appendline (text). Append (state). Append ("\ t").

Append ("Tomato clock length:"). Append (length. ToString ()). Appendline ("Minutes");

return s.tostring ();

}

}

}

The above is the entire code to share this article, I hope you can enjoy.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
C # The Tomato Clock countdown timer code

This address: http://www.paobuke.com/develop/c-develop/pbk23107.html






Related Content C # a way to read and write the contents of an XML file from an HTTP and FTP image address and display it on a ListView control how to implement callback function by delegate in C # easily learn the properties of C #
C # methods to get CPU numbers in C # call servlet sample C # to copy a Hashtable middle-key list or a list of values to a one-dimensional array C # property (Attribute) Usage Instance resolution

C # The Tomato Clock countdown timer code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.