30 days of. Net [Windows Mobile applications]-Day 01: minutes to midnight countdown (midnight countdown)

Source: Internet
Author: User

With the consent of original author Chris Craft, I can translate his seriesArticle30 days of. Net [Windows Mobile applications] and published in the blog. This is a very interesting series. Through this series of learning, you can master many Windows Mobile development skills, including GPS, Bluetooth, interface programming, multithreading, and so on.

In this series of articles, I will not translate them one by one. Instead, I will discuss the origin of the demand, the analysis and consideration of the demand, the expression of the implementation, and the ideas for improving the existing implementation, I hope to be a supplement to the original article. The first article is to implement a midnight countdown. For the original article, see DAY 01: minutes to midnight countdown

Requirement

The reason for this requirement is that the author Chris Craft intends to write a 30 days. net [Windows Mobile applications] developed a series of articles, and then thought about whether you have the determination to write, everyone has their own life: family, friends, career, interest has dreams. Everyone has 24 hours a day. We can know how much time is left on this day.

In fact, many times, we do things with our own thoughts, don't put them into action, or get rid of them halfway. At the beginning, the author also doubted whether he was determined to finish the work. The final result showed that Chris craft had done it. I also hope to learn from Chris Craft, read the articles in this series. If you are still out of Windows Mobile development, you can follow this series to learn a little bit every day, think a little, not much, too much, open the windows mobile development wonderful door, feel a little fun.

Preparations

To learn about this series, you must install Visual Studio 2008 and Windows Mobile 6 sdks. For Visual Studio 2008 express download, see Visual Studio Express. The Windows Mobile 6 SDK is downloaded from Windows Mobile 6 Professional and standard software development kits refresh.

Implementation

TheseProgramThe key is timer, datetime, and progress bar ).
Timer is used through the control, so the callback time is configured in the attribute as follows:

Figure 1

Figure 2
If interval is set to 100, timer_tick (Object sender, eventargs E) is called back every 100 milliseconds ).

 

Private   Void Timer_tick ( Object Sender, eventargs E)
{
Timespan = Datetime. Now. Date. adddays ( 1 ) - Datetime. now;
Labelhours. Text =   String . Format ( " {0} of 24 hours left " , Timespan. hours );
Labelminutes. Text =   String . Format ( " {0} of 60 minutes left " , Timespan. minutes );
Labelseconds. Text =   String . Format ( " {0} of 60 seconds left " , Timespan. Seconds );

Labeltotalminutes. Text =   String . Format ( " {0} of 1440 total minutes left " , Timespan. totalminutes. tostring ( " #. 0 " ));
Labeltotalseconds. Text =   String . Format ( " {0} of 86400 total seconds left " , Timespan. totalseconds );

progressbartotal. value = 86400 - ( int ) timespan. totalseconds;

progressbarhours. value = 24 - timespan. hours;
progressbarminutes. value = 60 - timespan. minutes;
progressbarseconds. value = 60 - timespan. seconds;

progressbartotalminutes. value = 1440 - ( int ) timespan. totalminutes;
progressbartotalseconds. value = 86400 - ( int ) timespan. totalseconds;
}

This callback functionAlgorithmIt is also very simple, datetime. now. date. adddays (1) retrieves the datetime object of the midnight time, and then subtract it from the current time to get the timespan object timespan. the time difference between the current and midnight timespan is displayed on the label and progressbar. On the total minutes left, the author makes a processing, because sometimes the decimal error "x.666666666 of 1440 total minutes left" is displayed ". timespan after string formatting. totalminutes. tostring ("#. 0 "), the display is normal.

Installation File: minutes2midnight. Cab

Source code: Minuates2midnight.zip

 

. NET Compact framework, WinCE, Windows Mobile Development Series

Jake's blog in blog Park --Simplified development and wireless life

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.