Creating A Simple Timer In Universal Windows App using Microsoft Visual Studio

Prerequisites

  • Visual Studio 2015.

Creating a Universal Windows app

Step 1 - Open Visual Studio 2015 and Click File ---> New ---> Project. It is the option for New Universal Windows app.

New

Step 2 - New Project Windows will open. Click Windows ---> Universal --->Blank app (Universal Windows) and type the name as Timer app  in Name box  and click OK button.

Blank App

Step 3 - Setting the platform Versions

Here, we choose the Target Version, Minimum Version for our Universal Windows Application and click OK button.

Versions

Step 4 - Now, we go to Solution Explorer and open Main Page.xaml to design the page.

 Solution Explorer

Step 5 - Designing the App in UWP

In Main Page.xaml designing page, drag the button control from the tool box. Go to Property Window, change the name as Startbutton and content to start Timer.

button

Step 6 - Next, drag the next button control from the tool box and go to the Property Window. Change the name to Stopbutton and content to stop Timer.

button

Step 7 - Last, drag the Textblock control from the tool box and go to the Property Window, change the name to Displaytext and content is  kept as empty.

Textblock

Step 8 - Add the Coding

To add the coding, double click on the Start Timer button, add the mentioned source code and type the source code. 
  1. private void Startbutton_Click(object sender, RoutedEventArgs e) 
  2. {  
  3.    Timmer.Start();  
  4. }   
Double click on the Stop Timer button and add the mentioned source code.
  1. private void Stopbutton_Click(object sender, RoutedEventArgs e) 
  2. {  
  3.    Displaytext.Text = Timmer.Elapsed.ToString();  
  4.    string milliseconds = Timmer.ElapsedMilliseconds.ToString();  
  5.    Timmer.Stop();  
  6. }   
Add the coding, given below-

code
 
Add the header file, given below-
 
Finally, the coding Window looks, as given below-

coding window

Step 9 - Run the Application by clicking the Local Machine to run the Application. 

Application

Output

Output

Output

Up Next
    Ebook Download
    View all
    Learn
    View all