Countdown control, countdown Software

Source: Internet
Author: User

Countdown control, countdown Software

Recently, a small WPF project needs to use a timer. Therefore, a timer control is written and recorded for the next time.

 

Front-end XAML:

<UserControl x: Class = "Test. CountDown" xmlns =" http://schemas.microsoft.com/winfx/2006/xaml /Presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "Xmlns: mc =" http://schemas.openxmlformats.org/markup-compatibility/2006 "Xmlns: d =" http://schemas.microsoft.com/expression/blend/2008 "Mc: Ignorable =" d "d: DesignHeight =" 110 "d: DesignWidth =" 150 "> <Grid. columnDefinitions> <ColumnDefinition Width = "43 *"/> <ColumnDefinition Width = "13"/> <ColumnDefinition Width = "43 *"/> <ColumnDefinition Width = "13"/> <ColumnDefinition Width = "43 *"/> </Grid. columnDefinitions> <TextBlock Text = "00" Name = "HourArea" verticalignment = "Center" FontSize = "30" Background = "Transparent" Grid. column = "0" Foreground = "DarkOrange"/> <TextBlock Text = ": "Name =" HourSplitMinute "verticalignment =" Center "FontSize =" 30 "Background =" Transparent "Grid. column = "1" Foreground = "DarkOrange"/> <TextBlock Text = "00" Name = "MinuteArea" verticalignment = "Center" FontSize = "30" Background = "Transparent" Grid. column = "2" Foreground = "DarkOrange"/> <TextBlock Text = ": "Name =" MinuteSplitSecond "verticalignment =" Center "FontSize =" 30 "Background =" Transparent "Grid. column = "3" Foreground = "DarkOrange"/> <TextBlock Text = "00" Name = "SecondArea" verticalignment = "Center" FontSize = "30" Background = "Transparent" Grid. column = "4" Foreground = "DarkOrange"/> </Grid> </UserControl>View Code

 

Background logic:

Public partial class CountDown: UserControl {public DispatcherTimer timer; public Process pro; public Stopwatch sw = new Stopwatch (); public int seconds; public CountDown () {InitializeComponent (); pro = new Process (); timer = new DispatcherTimer (); timer. interval = new TimeSpan (0, 0, 1); timer. tick + = new EventHandler (timer_Tick);} void timer_Tick (object sender, EventArgs e) {TimeSpan ts = new TimeSpan (0, 0, seconds); pro. totalSecond = (int) (ts-sw. elapsed ). totalSeconds; if (pro. totalSecond> 0) {HourArea. text = pro. getHour (); MinuteArea. text = pro. getMinute (); SecondArea. text = pro. getSecond ();} else {timer. stop (); sw. stop (); sw. reset (); SecondArea. text = string. format ("{0: D2}", 0) ;}} public class Process {public int totalSecond; // obtain the hour string public string GetHour () {return string. format ("{0: D2}", totalSecond/3600);} // obtain the minute string public string GetMinute () {return string. format ("{0: D2}", (totalSecond/60-(int) (totalSecond/3600) * 60 )));} // obtain the second string public string GetSecond () {return string. format ("{0: D2}", totalSecond % 60 );}}View Code

 

Call:

This. countDown1.seconds = 300; // total input countdown time (seconds) this. countDown1.timer. Start (); this. countDown1.sw. Start ();

 


Excel countdown control settings

In my Baidu space, I have an article "Countdown timer", which provides production methods for reference. There is code in it. Please refer to it.
Hi.baidu.com/..13d6e1

Use the VB clock control to create a countdown

'Add a label
Dim timep As Integer
Private Sub commandementclick ()
Text1.Enabled = True
Timer1.Enabled = True
Timer1.integer = 1000
Time P = 120
End Sub

Private Sub Timer1_Timer ()
Timep = timep-1
Label1.Caption = Format (timep \ 60, "00") & ":" & Format (timep Mod 60, "00 ")
If timep = 0 Then
Text1.Enabled = False
Timer1.Enabled = False
End If

End Sub

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.