Software & Finance





Visual Studio.NET - SilverLight Application For Finding the Area and Periemeter of a Triangle Given 3 sides





Here is the SilverLight Application Source code and downloadable for finding the Area and Periemeter of a Triangle Given 3 sides.

 

Click here to download the SilverLight Project in VS2010

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace TriangleSide_AreaPerimeter

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

        }

 

        private void Calculate_Click(object sender, RoutedEventArgs e)

        {

            double a = Convert.ToDouble(SideA.Text);

            double b = Convert.ToDouble(SideB.Text);

            double c = Convert.ToDouble(SideC.Text);

 

            double perimeter = (a + b + c);

            ResultP.Text = perimeter.ToString();

 

            double s = 0.5 * perimeter;

            double area = Math.Sqrt(s * (s - a) * (s - b) * (s - c));

            ResultA.Text = area.ToString();

        }

    }

}

 

<UserControl x:Class="TriangleSide_AreaPerimeter.MainPage"

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

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

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

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

    mc:Ignorable="d"

    d:DesignHeight="180" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="#eeeeee">

 

        <Grid.RowDefinitions>

            <RowDefinition Height="50"></RowDefinition>

            <RowDefinition Height="50"></RowDefinition>

            <RowDefinition Height="50"></RowDefinition>

        </Grid.RowDefinitions>

 

        <TextBlock Grid.Row="0" HorizontalAlignment="Left" Margin="10,15,0,0" VerticalAlignment="Center" Text="Side A: " Height="20"></TextBlock>

        <TextBlock Grid.Row="0" HorizontalAlignment="Left" Margin="130,15,0,0" VerticalAlignment="Center" Text="Side B: " Height="20"></TextBlock>

        <TextBlock Grid.Row="0" HorizontalAlignment="Left" Margin="250,15,0,0" VerticalAlignment="Center" Text="Side C: " Height="20"></TextBlock>

        <TextBox Grid.Row="0" HorizontalAlignment="Left" Margin="60,10,0,0" Name="SideA" Width="60" Height="25"></TextBox>

        <TextBox Grid.Row="0" HorizontalAlignment="Left" Margin="180,10,0,0" Name="SideB" Width="60" Height="25"></TextBox>

        <TextBox Grid.Row="0" HorizontalAlignment="Left" Margin="300,10,0,0" Name="SideC" Width="60" Height="25"></TextBox>

 

        <TextBlock Grid.Row="2" HorizontalAlignment="Left" Margin="10,15,0,0" VerticalAlignment="Center" Text="Area: " Height="20"></TextBlock>

        <TextBlock Grid.Row="2" HorizontalAlignment="Left" Margin="200,15,0,0" VerticalAlignment="Center" Text="Perimeter: " Height="20"></TextBlock>

        <TextBox Grid.Row="2" HorizontalAlignment="Left" Margin="70,10,0,0" Name="ResultA" Width="100" Height="25"></TextBox>

        <TextBox Grid.Row="2" HorizontalAlignment="Left" Margin="260,10,0,0" Name="ResultP" Width="100" Height="25"></TextBox>

 

        <Button Grid.Row="1" HorizontalAlignment="Left" Margin="50,0,0,0" Click="Calculate_Click" Content="Calculate Area and Perimeter the Triangle" Width="250" Height="25"></Button>

    </Grid>

</UserControl>