Using System. Collections. Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. The Text;
Using System. Windows. Forms;
The namespace countdown
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent ();
}
//define global variables, minutes and seconds
Int minute;
Int second;
Private void but_start_Click (object sender, EventArgs e)
{
//to assign values to the minutes and seconds
Minute=int. Parse (txt_show. Text. The Substring (0, 2));
Second=int. Parse (txt_show. Text. The Substring (3, 2));
//start the time
Timer1. Enabled=true;
Timer1. Interval=1000;
Timer1. Start ();
}
Private void but_stop_Click (object sender, EventArgs e)
{
//stop timing
Timer1. Stop ();
}
Private void timer1_Tick (object sender, EventArgs e)
{
//SEC to 0 to seconds from the new assignment
If (second==0)
{
Second=60;
}
//the decrement
- the second;
If (second==59)
{
Minute -;
}
//change the output format
If (second & lt; 10)
{
Txt_show. Text=minute. ToString () + ":" + "0" + second. The ToString ();
}
The else
{
If (minute & lt; 10)
{
Txt_show. Text="0" + minute. ToString () + ":" + second. The ToString ();
}
The else
{
Txt_show. Text=minute. ToString () + ":" + second. The ToString ();
}
}
//if the countdown, to 0
If (minute==0 & amp; & Second==0)
{
This. The timer1. Stop ();
Minute=second=0;
}
}
}
}
I am a freshman and had just begun to learn, what are the wrong place please advise, QQ2524143038!
CodePudding user response:
Always awesomeCodePudding user response:
With DataTime. Now () get instant of time, computing and start timing time of fragments, the timer time is not very accurate, have to use count, you can use the TimeSpan this structure, you can simplify your program statements and calculation logic,CodePudding user response:
Very goodCodePudding user response:
Timer this control used to trigger the focus is on timing trigger. But his high accuracy is not generally considered. Advice to see System. Diagnostics. Stopwatch class - this classCodePudding user response:
CanCodePudding user response: