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

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

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 TrianglePoint_AreaPerimeter

{

public partial class MainPage : UserControl

{

public MainPage()

{

InitializeComponent();

}

private void Calculate_Click(object sender, RoutedEventArgs e)

{

double ax = Convert.ToDouble(PointX1.Text);

double ay = Convert.ToDouble(PointY1.Text);

double bx = Convert.ToDouble(PointX2.Text);

double by = Convert.ToDouble(PointY2.Text);

double cx = Convert.ToDouble(PointX3.Text);

double cy = Convert.ToDouble(PointY3.Text);

double area = (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by)) / 2;

area = Math.Abs(area);

double a = Math.Sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));

double b = Math.Sqrt((bx - cx) * (bx - cx) + (by - cy) * (by - cy));

double c = Math.Sqrt((cx - ax) * (cx - ax) + (cy - ay) * (cy - ay));

double perimeter = a + b + c;

ResultA.Text = area.ToString();

ResultP.Text = perimeter.ToString();

}

}

}

<UserControl x:Class="TrianglePoint_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="280" d:DesignWidth="400">

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

<Grid.RowDefinitions>

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

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

<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="Point X1: " Height="20"></TextBlock>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

</Grid>

</UserControl>