Home > Net >  C # do a simple timer (00:00) novice please come in, big detours!
C # do a simple timer (00:00) novice please come in, big detours!

Time:09-26

using System;
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 awesome

CodePudding 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 good

CodePudding 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 class

CodePudding user response:

Can

CodePudding user response:

reference 4 floor qq_29363771 response:
timer this control used to trigger the focus is on timing trigger. But his high accuracy is not generally considered. Suggest see System. Diagnostics. Stopwatch class - this class

Ok, thank you, this is very simple a timer so don't want to some functions to make calls

CodePudding user response:

Thank you for your bosses to give advice!!!!!!
  •  Tags:  
  • C#
  • Related