Software & Finance





Visual Studio.NET - SilverLight Application For Simple Addition, Subtraction, Division and Multiplication





Here is the SilverLight Application Source code and downloadable for Simple Addition, Subtraction, Division and Multiplication.

 

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 Silverlight_SimpleArithmetic

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

            Combo1.SelectedIndex = 0;

        }

 

        private void Compute_Click(object sender, RoutedEventArgs e)

        {

            decimal result = 0;

            decimal operand1 = System.Convert.ToDecimal(Text1.Text);

            decimal operand2 = System.Convert.ToDecimal(Text2.Text);

 

            int nIndex = Combo1.SelectedIndex;

            if(nIndex == 0)

                result = operand1 + operand2;

           else if(nIndex == 1)

                result = operand1 - operand2;

            else if(nIndex == 2)

                result = operand1 * operand2;

            else if(nIndex == 3)

                result = operand1 / operand2;

 

            Text3.Text = result.ToString();

        }

    }

}

 <UserControl x:Class="Silverlight_SimpleArithmetic.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="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

 

        <ComboBox Height="23" Name ="Combo1" HorizontalAlignment="Left" Margin="129,31,0,0" VerticalAlignment="Top" Width="60" >

            <ComboBoxItem Content="+"/>

            <ComboBoxItem Content="-"/>

            <ComboBoxItem Content="*"/>

            <ComboBoxItem Content="/"/>

        </ComboBox>

        <TextBox Height="23" Name ="Text1" HorizontalAlignment="Left" Margin="129,61,0,0" VerticalAlignment="Top" Width="120" />

        <TextBox Height="23" Name ="Text2" HorizontalAlignment="Left" Margin="129,91,0,0" VerticalAlignment="Top" Width="120" />

        <TextBox Height="23" Name ="Text3" HorizontalAlignment="Left" Margin="129,137,0,0" VerticalAlignment="Top" Width="120" />

        <TextBlock Height="23" HorizontalAlignment="Left" Margin="57,32,0,0" Name="textBlock3" Text="Operation: " VerticalAlignment="Top" />

        <TextBlock Height="23" HorizontalAlignment="Left" Margin="57,62,0,0" Name="textBlock1" Text="Number1: " VerticalAlignment="Top" />

        <TextBlock Height="23" HorizontalAlignment="Left" Margin="57,92,0,0" Name="textBlock2" Text="Number2: " VerticalAlignment="Top" />

        <Button Content="Compute" Height="22" HorizontalAlignment="Left" Margin="57,137,0,0" Name="button1" VerticalAlignment="Top" Width="55" Click="Compute_Click" />

    </Grid>

 

</UserControl>

 

 

Hosting code is given below:

 

<body>

    <form id="form1" runat="server" style="height:100%">

    <div id="silverlightControlHost">

        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">

              <param name="source" value="Silverlight_SimpleArithmetic.xap"/>

              <param name="onError" value="onSilverlightError" />

              <param name="background" value="white" />

              <param name="minRuntimeVersion" value="3.0.40818.0" />

              <param name="autoUpgrade" value="true" />

              <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration:none">

                    <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>

              </a>

          </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

    </form>

</body>

 

 

 

 


The following is the run time output of silverlight application.