Now we will see how to create a UWP for calculating the reverse of an entered number. First open Visual Studio IDE 2017, then Open new project.Then, select Visual C# and Blank App.
Now, select the Target Version and Minimum Version.
Now, in solution explorer open MainPage.xaml.
Now in toolbox select the TextBlock and drag it on the screen.
In toolbox select TextBox and drag it on the screen.
Now again repeat the same for TextBlock and for TextBox. And in toolbox select Button and drag it on the screen.
And now edit the properties of TextBlocks,TextBoxes and Button and your screen will appear like this
Now the xaml code will be,
- <Page x:Class="Reverse_Of_Number.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Reverse_Of_Number" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
- <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
- <TextBlock x:Name="tbnum" HorizontalAlignment="Left" Height="99" Margin="286,214,0,0" Text="Enter any number:" TextWrapping="Wrap" VerticalAlignment="Top" Width="353" FontSize="36" />
- <TextBox x:Name="txtnum" HorizontalAlignment="Left" Height="84" Margin="687,210,0,0" Text="" VerticalAlignment="Top" Width="376" FontSize="36" />
- <TextBlock x:Name="tbres" HorizontalAlignment="Left" Height="72" Margin="298,341,0,0" Text="Result:" TextWrapping="Wrap" VerticalAlignment="Top" Width="333" FontSize="36" />
- <TextBox x:Name="txtres" HorizontalAlignment="Left" Height="72" Margin="679,325,0,0" Text="" VerticalAlignment="Top" Width="392" FontSize="36" />
- <Button x:Name="btncal" Content="Calculate" HorizontalAlignment="Left" Height="100" Margin="456,476,0,0" VerticalAlignment="Top" Width="417" FontSize="36" /> </Grid>
- </Page>
Now double click on the Button and it will open a .cs file and then write the code in that file
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices.WindowsRuntime;
- using Windows.Foundation;
- using Windows.Foundation.Collections;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Controls.Primitives;
- using Windows.UI.Xaml.Data;
- using Windows.UI.Xaml.Input;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Navigation;
-
- namespace Reverse_Of_Number {
-
-
-
- public sealed partial class MainPage: Page {
- public MainPage() {
- this.InitializeComponent();
- }
- private void btncal_Click(object sender, RoutedEventArgs e) {
- int n = Convert.ToInt32(txtnum.Text);
- int t, rev = 0;
- while (n != 0) {
- t = n % 10;
- rev = rev * 10 + t;
- n = n / 10;
- }
- txtres.Text = rev.ToString();
- }
- }
- }
And your screen will be displayed like this
Now execute the UWP application, after executing enter the number and your screen will be dispalyed like this
If we enter 0 at last position then the result will be,
In the second case we have entered 0 at the one's place and we have 5 digits but, after finding the reverse number we will get 4 digits.
Because if any number has 0 in front of any number eg., 10 is a number and reverse of this is 01 and we say it is 1. Like in the same way 85670's reverse number is 07658 and we say it is 7658. Now we have successfully created an UWP application that finds the reverse of the entered number.