In this article you will learn how to create a table of a particular number entered by you. Just like the counting table that we saw in earlier classes. Now the table logic is implemented in a Windows Store  app.

Use the following procedure to create the table in a Windows Store app.

Step 1

First of all you have to create a New Window Store Application, as in the following:

  • Open Visual Studio 2012
  • "File" -> "New" -> "Project..."
  • Choose Template: "Visual C#" -> "Window Store app"
  • "Blank App (XAML)", then rename the application

new-windows-store-app.jpg

Step 2

Write the following simple XAML code for "Mainpage.Xaml" (that is available in Solution Explorer):

<Page

    x:Class="table_app.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="using:table_app"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d">

 

    <Grid Background="Red">

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="461*"/>

            <ColumnDefinition Width="905*"/>

        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>

            <RowDefinition Height="97*"/>

            <RowDefinition Height="52*"/>

            <RowDefinition Height="50*"/>

            <RowDefinition Height="46*"/>

            <RowDefinition Height="523*"/>

        </Grid.RowDefinitions>

        <TextBlock Text="Create Table App" FontSize="20" FontFamily="Arial" FontWeight="ExtraBold" Foreground="White" Grid.Column="1" Grid.Row="1"/>

        <TextBlock Text="Enter number" FontSize="20" FontFamily="Arial" FontWeight="ExtraBold" Foreground="White" Grid.Column="0" Grid.Row="2" TextAlignment="Right"></TextBlock>

        <TextBox x:Name="textbox1" Grid.Column="1" Grid.Row="2" Width="200" Height=" 25" HorizontalAlignment="Left" VerticalAlignment="Top" ></TextBox>

        <Button x:Name="button1" Content="Click" Click="button1_Click" Grid.Column="1" Grid.Row="3" Background="Yellow" Foreground="Black" Margin="0,4" Width="118" ></Button>

        <TextBlock x:Name="text1" Grid.Column="1" Grid.Row="4" TextWrapping="Wrap" Width="794"  HorizontalAlignment="Left" Margin="0,0,0,75" FontSize="15" FontWeight="ExtraBold" ></TextBlock>               

    </Grid>

</Page>

 

Step 3

Now write the following C# code for the button within "Mainpage.Xaml.cs":

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

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 table_app

    public sealed partial class MainPage : Page

    {

        public MainPage()

        {

            this.InitializeComponent();

        }      

        protected override void OnNavigatedTo(NavigationEventArgs e)

        {

        }

        private void button1_Click(object sender, RoutedEventArgs e)

        {

            int num = 0, i;

            num = Convert.ToInt32(textbox1.Text);

            for (i = 1; i <= 10; i++)

            {

                text1.Text += num + "*" + i + "=" + (num * i);

                text1.Text += Environment.NewLine;

            }

        }

    }

}

 

Step 4

Run your app.

run-table-app.jpg

output-of-table-app.jpg

Next Recommended Readings