Software & Finance





Visual Studio.NET - SilverLight Application For Finding the line equation given two points





Here is the SilverLight Application Source code and downloadable for finding the line equation given two points.

 

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 LineEqn_2Points

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

        }

 

        private void Find_Click(object sender, RoutedEventArgs e)

        {

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

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

 

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

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

 

            double slope = (y1 - y2) / (x1 - x2);

            double intercept = y1 - (slope * x1);

 

            Result.Text = "Y = " + slope.ToString() + "X + " + intercept.ToString();

        }

    }

}

 

 

<UserControl x:Class="LineEqn_2Points.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="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>

 

        <Button Grid.Row="2" HorizontalAlignment="Left" Margin="50,0,0,0" Click="Find_Click" Content="Find Line Equation" Width="150" Height="25"></Button>

        <TextBox Grid.Row="2" HorizontalAlignment="Left" Margin="220,0,0,0" Name="Result" Width="150" Height="25"></TextBox>

    </Grid>

</UserControl>