C# learning summary (5) - implementation of countdown function

I'm working on the content of the experiment report left by the teacher tonight. One of the experiments includes a countdown function. The first time I saw it, I was confused about how to write it. Then I read the experiment instructions and used the timer in C#... and then did it in seconds. Done.


Timer—Timer

Add Timer control

Find Timer in the toolbox and double-click to add it. After adding it, find its properties and modify the Interval property, that is, the interval execution time.


Add Timer execution code

Double-click the Timer control (you can also add it to its events, just one event) to add a Tick event. That is, the code to be executed every once in a while.


Turn on/off Timer

Use the name of the Timer control to directly call the Start() method or Stop() method


DateTime—date type

 //设置时间(10分钟)
 DateTime dt = DateTime.Parse("10:00:00");
 //减一秒钟
 dt = dt.AddSeconds(-1);
 //输出时间
 string time = dt.ToLongTimeString().ToString();

There are a lot of descriptions about DateTime on the Internet, so I won't make any special instructions.


Since the total code involves a lot of things, I won't put it up. Pay attention to when the timer starts and ends, and the condition for the end is fine .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325985125&siteId=291194637
Recommended