In this article I explain how to print pyramids in a Windows Store app. Generally printing pyramids is very common in the C language. But later printing a pyramid has become common in C#. But to print a pyramid in a Windows Form is not an easy job. So here I will describe how to a print pyramid in a Windows Store app.

To Print the pyramid in Windows Store app do the following steps.

Step 1

First of all you have to create a New Window Store 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="Pyramid_app.MainPage"

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

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

xmlns:local="using:Pyramid_app"

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

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

mc:Ignorable="d">

<Grid Background="Blue">

<Grid.ColumnDefinitions>

<ColumnDefinition Width="661*"/>

<ColumnDefinition Width="705*"/>

</Grid.ColumnDefinitions>

<Grid.RowDefinitions>

<RowDefinition Height="143*"/>

<RowDefinition Height="38*"/>

<RowDefinition Height="43*"/>

<RowDefinition Height="300*"/>

<RowDefinition Height="0*"/>

<RowDefinition Height="39*"/>

<RowDefinition Height="205*"/>

</Grid.RowDefinitions>

<TextBlock Text="Print Pyramid" FontSize="25" FontWeight="ExtraBold" Grid.ColumnSpan="2" Grid.Row="1" TextAlignment="Center" Foreground="Red" ></TextBlock>

<TextBlock Text="Enter Line no:" FontSize="25" FontWeight="ExtraBold" Grid.Column="0" Grid.Row="2" Foreground="Red" TextAlignment="Right"> </TextBlock>

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

<TextBlock x:Name="text1" FontSize="25" FontWeight="ExtraBold" Grid.Column="1" Grid.Row="3" Foreground="Red" TextWrapping="Wrap" Width="466" HorizontalAlignment="Left" />

<Button x:Name="Button1" Content="Click" Click="Button1_Click" Foreground="Red" Background="Yellow" Grid.Column="1" Grid.Row="1" Height="44" Width="141" VerticalAlignment="Top" Grid.RowSpan="2" HorizontalAlignment="Center" Margin="148,37,416,0" />

</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 Pyramid_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)

{

text1.Text = "";

int range = Convert.ToInt32(textbox1.Text);

{
for (int j = 1; j <= i; j++)
{
text1.Text +=
"*";

}

text1.Text += Environment.NewLine;
}

}
}
}

Step 4

Run your App.

Run-pyramid-app.jpg

output-of-pyramid-app.jpg