2. ПРАКТИЧНА РЕАЛІЗАЦІЯ
2.1.Завдання проекту
Розробити проект “Calculator_Prod_Azaza” в середовищі візуального програмування Visual Studio Express 2013 для Windows Phone. Програма створена для використання у навчальних цілях. За допомогою цього додатку можна здійснювати елементарні математичні обрахунки, такі як: «Додавання», «Віднімання», «Множення», «Ділення» і «Піднесення до квадрату». У кінцевому результаті додаток має виглядати так (Рис. 2.1.1.):
Рис. 2.1.1. Кінцевий вигляд додатку
2.2.Блок-схема
Рис.2.2.1. Блок-схема програми
2.3.Вихідний код програми
Код файлу MainPage.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Сalculator_Prod_Azaza.Resources;
namespace Сalculator_Prod_Azaza
{
public partial class MainPage : PhoneApplicationPage
{
// Конструктор
public MainPage()
{
InitializeComponent();
// Пример кода для локализации ApplicationBar
//BuildLocalizedApplicationBar();
}
private void Number_Click(object sender, RoutedEventArgs e)
{
Button b = (Button)sender;
TextBox.Text += b.Content.ToString();
}
private void buttonrezult_Click(object sender, RoutedEventArgs e)
{
String op;
int iop=0;
if (TextBox.Text.Contains("+"))
{
iop = TextBox.Text.IndexOf("+");
}
else if (TextBox.Text.Contains("-"))
{
iop = TextBox.Text.IndexOf("-");
}
if (TextBox.Text.Contains("*"))
{
iop = TextBox.Text.IndexOf("*");
}
if (TextBox.Text.Contains("/"))
{
iop = TextBox.Text.IndexOf("/");
}
else
{
}
op = TextBox.Text.Substring(iop, 1);
double op1 = Convert.ToDouble(TextBox.Text.Substring(0, iop));
double op2 = Convert.ToDouble(TextBox.Text.Substring(iop+1,TextBox.Text.Length - iop-1));
if (op=="+")
{
TextBox.Text += "=" + (op1 + op2);
}
if (op == "-")
{
TextBox.Text += "=" + (op1 - op2);
}
if (op == "*")
{
TextBox.Text += "=" + (op1 * op2);
}
if (op == "/")
{
TextBox.Text += "=" + (op1 / op2);
}
}
private void buttoncc_Click(object sender, RoutedEventArgs e)
{
TextBox.Text = "";
}
private void buttonx2_Click(object sender, RoutedEventArgs e)
{
try
{
double rezult = Math.Pow(int.Parse(TextBox.Text), 2);
TextBox.Text = rezult.ToString();
}
catch
{
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
text1.Visibility = Visibility.Collapsed;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
text1.Visibility = Visibility.Visible;
}
private void text1_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
control2.Visibility = Visibility.Visible;
ContentPanel.Visibility = Visibility.Collapsed;
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
control2.Visibility = Visibility.Collapsed;
ContentPanel.Visibility = Visibility.Visible;
}
private void Button_Click_4(object sender, RoutedEventArgs e)
{
text3.Visibility = Visibility.Visible;
control2.Visibility = Visibility.Collapsed;
button.Visibility = Visibility.Visible;
}
private void Button_Click_5(object sender, RoutedEventArgs e)
{
text3.Visibility = Visibility.Collapsed;
control2.Visibility = Visibility.Visible;
button.Visibility = Visibility.Collapsed;
}
private void Button_Click_6(object sender, RoutedEventArgs e)
{
control2.Visibility = Visibility.Visible;
control3.Visibility = Visibility.Collapsed;
}
private void Button_Click_7(object sender, RoutedEventArgs e)
{
control3.Visibility = Visibility.Visible;
control2.Visibility = Visibility.Collapsed;
}
private void button55_Click(object sender, RoutedEventArgs e)
{
text5.Visibility = Visibility.Collapsed;
control3.Visibility = Visibility.Visible;
button55.Visibility = Visibility.Collapsed;
}
private void Button_Click_8(object sender, RoutedEventArgs e)
{
text5.Visibility = Visibility.Visible;
control3.Visibility = Visibility.Collapsed;
button55.Visibility = Visibility.Visible;
}
private void Button_Click_9(object sender, RoutedEventArgs e)
{
text6.Visibility = Visibility.Collapsed;
control3.Visibility = Visibility.Visible;
button66.Visibility = Visibility.Collapsed;
}
private void Button_Click_10(object sender, RoutedEventArgs e)
{
text6.Visibility = Visibility.Visible;
control3.Visibility = Visibility.Collapsed;
button66.Visibility = Visibility.Visible;
}
private void button77_Click(object sender, RoutedEventArgs e)
{
text7.Visibility = Visibility.Collapsed;
control3.Visibility = Visibility.Visible;
button77.Visibility = Visibility.Collapsed;
}
private void Button_Click_11(object sender, RoutedEventArgs e)
{
text7.Visibility = Visibility.Visible;
control3.Visibility = Visibility.Collapsed;
button77.Visibility = Visibility.Visible;
}
private void Button_Click_12(object sender, RoutedEventArgs e)
{
text8.Visibility = Visibility.Collapsed;
control3.Visibility = Visibility.Visible;
button88.Visibility = Visibility.Collapsed;
}
private void Button_Click_13(object sender, RoutedEventArgs e)
{
text8.Visibility = Visibility.Visible;
control3.Visibility = Visibility.Collapsed;
button88.Visibility = Visibility.Visible;
}
private void Button_Click_14(object sender, RoutedEventArgs e)
{
text9.Visibility = Visibility.Collapsed;
control3.Visibility = Visibility.Visible;
button99.Visibility = Visibility.Collapsed;
}
private void Button_Click_15(object sender, RoutedEventArgs e)
{
text9.Visibility = Visibility.Visible;
control3.Visibility = Visibility.Collapsed;
button99.Visibility = Visibility.Visible;
}
Код файлу MainPage.xaml:
<phone:PhoneApplicationPage x:Name="grid2"
x:Class="Сalculator_Prod_Azaza.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Coral">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="14,84,-2,10">
<TextBlock Text="Калькулятор" TextAlignment="Center" Foreground="Indigo" Margin="0,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto" HorizontalAlignment="Right" Width="459">
<TextBlock.RenderTransform>
<CompositeTransform Rotation="-355.006" SkewX="-14.03" TranslateX="-11.92" TranslateY="-1.042"/>
</TextBlock.RenderTransform>
</TextBlock>
</StackPanel>
<!--ContentPanel — поместите здесь дополнительное содержимое-->
<Grid x:Name="ContentPanel" Margin="14,10,10,-10" Grid.Row="1" Background="Coral">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="71*"/>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="39*"/>
</Grid.ColumnDefinitions>
<Button Content="7" Name="button7" Background="DarkBlue" HorizontalAlignment="Left" Height="76" Margin="9,387,0,0" VerticalAlignment="Top" Width="106" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
<Button.RenderTransform>
<CompositeTransform SkewX="1.469" TranslateX="0.974"/>
</Button.RenderTransform>
</Button>
<Button Click="Number_Click" Content="8" Name="button8" Background="DarkBlue" HorizontalAlignment="Left" Height="76" Margin="121,391,0,0" VerticalAlignment="Top" Width="106"/>
<Button Click="Number_Click" Content="9" Name="button9" Background="DarkBlue" HorizontalAlignment="Left" Height="76" Margin="222,391,0,0" VerticalAlignment="Top" Width="106" RenderTransformOrigin="1.83,-3.658" Grid.ColumnSpan="3"/>
<Button Click="Number_Click" Content="*" FontSize="30" Name="buttonmnog" Background="DarkGray" HorizontalAlignment="Left" Height="76" Margin="28,391,0,0" VerticalAlignment="Top" Width="106" Grid.Column="2"/>
<Button Click="Number_Click" Content="/" FontSize="30" Name="buttondiv" Background="DarkGray" HorizontalAlignment="Left" Height="76" Margin="28,467,0,0" VerticalAlignment="Top" Width="106" Grid.Column="2"/>
<Button Click="buttonrezult_Click" Content="=" Name="buttonrezult" Background="DarkGreen" HorizontalAlignment="Left" Height="76" Margin="222,467,0,0" VerticalAlignment="Top" Width="106" Grid.ColumnSpan="3"/>
<Button Click="Number_Click" Content="0" Name="button0" Background="DarkBlue" HorizontalAlignment="Left" Height="76" Margin="116,467,0,0" VerticalAlignment="Top" Width="106"/>
<Button Click="buttoncc_Click" Content="C" Name="buttoncc" Background="Red" HorizontalAlignment="Left" Height="76" Margin="10,163,0,0" VerticalAlignment="Top" Width="212"/>
<Button Click="buttonx2_Click" Content="X2" Name="buttonx2" Background="CornflowerBlue" HorizontalAlignment="Left" Height="76" Margin="222,163,0,0" VerticalAlignment="Top" Width="212" Grid.ColumnSpan="3"/>
<Button Click="Number_Click" Content="1" Name="button1" Background="DarkBlue" HorizontalAlignment="Left" Height="76" Margin="10,239,0,0" VerticalAlignment="Top" Width="106" RenderTransformOrigin="1.906,-4.132"/>
<Button Click="Number_Click" Content="2" Name="button2" Background="DarkBlue" HorizontalAlignment="Left" Height="76" Margin="116,239,0,0" VerticalAlignment="Top" Width="106"/>
<Button Click="Number_Click" Content="3" Name="button3" Background="DarkBlue" HorizontalAlignment="Left" Height="76" Margin="222,239,0,0" VerticalAlignment="Top" Width="106" RenderTransformOrigin="2.151,-4.289" Grid.ColumnSpan="3"/>
<Button Click="Number_Click" Content="+" FontSize="30" Name="buttonplus" Background="DarkGray" HorizontalAlignment="Left" Height="76" Margin="28,239,0,0" VerticalAlignment="Top" Width="106" RenderTransformOrigin="2.415,-4.211" Grid.Column="2"/>
<Button Click="Number_Click" Content="4" Name="button4" Background="DarkBlue" HorizontalAlignment="Left" Height="76" Margin="10,315,0,0" VerticalAlignment="Top" Width="106"/>
<Button Click="Number_Click" Content="5" Name="button5" Background="DarkBlue" HorizontalAlignment="Left" Height="76" Margin="121,315,0,0" VerticalAlignment="Top" Width="106"/>
<Button Click="Number_Click" Content="6" Name="button6" Background="DarkBlue" HorizontalAlignment="Left" Height="76" Margin="222,315,0,0" VerticalAlignment="Top" Width="106" Grid.ColumnSpan="3"/>
<Button Click="Number_Click" Content="-" FontSize="30" Name="buttonminys" Background="DarkGray" HorizontalAlignment="Left" Height="76" Margin="28,315,0,0" VerticalAlignment="Top" Width="106" RenderTransformOrigin="2.075,-4.395" Grid.Column="2"/>
<Button Click="Number_Click" Content="00" Name="button00" Background="DarkBlue" HorizontalAlignment="Left" Height="76" Margin="13,467,0,0" VerticalAlignment="Top" Width="106" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
<Button.RenderTransform>
<CompositeTransform SkewX="1.469" TranslateX="0.974"/>
</Button.RenderTransform>
</Button>
<TextBox Name="TextBox" HorizontalAlignment="Left" Height="163" Margin="17,0,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="429" Grid.ColumnSpan="3"/>
</Grid>
<Button Content=" Продовжити роботу" HorizontalAlignment="Left" Height="74" Margin="187,0,0,0" VerticalAlignment="Top" Width="57" Click="Button_Click" Background="#FFF03838" Foreground="#FF2424D1"/>
<Button Content="Про програму" HorizontalAlignment="Left" Height="74" VerticalAlignment="Top" Width="214" Click="Button_Click_1" Background="#FF22D632" Foreground="#FFDE5757"/>
<TextBox HorizontalAlignment="Left" Name="text1" Height="722" TextWrapping="Wrap" Text="Мобільний додаток "Калькулятор" створений для використання у навчальних цілях. За допомогою цього додатку можна здійснювати елементарні математичні обрахунки. 
Розробник: Тимків Михайло
Дата розробки проекту: 17.01.17
Сумісність з ОС: Windows Phone 8.1
" VerticalAlignment="Top" Width="480" Grid.RowSpan="2" FontFamily="Lucida Handwriting" FontSize="33" TextAlignment="Center" Foreground="#FFB9F191" FontStyle="Italic" TextChanged="text1_TextChanged" Margin="2,56,-2,-10" Visibility="Collapsed">
<TextBox.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="1"/>
<GradientStop Color="#FF3375C3" Offset="0.81"/>
</LinearGradientBrush>
</TextBox.Background>
</TextBox>
<Button Content="Додатково" HorizontalAlignment="Left" Height="74" Margin="286,0,0,109" VerticalAlignment="Bottom" Width="184" Background="#FFC711B6" Click="Button_Click_2"/>
<Grid x:Name="control2" HorizontalAlignment="Left" Height="539" Margin="44,160,0,0" VerticalAlignment="Top" Width="426" Grid.RowSpan="2" Visibility="Collapsed">
<Button Content="Розклад дзвінків" HorizontalAlignment="Left" Height="130" Margin="-10,126,0,0" VerticalAlignment="Top" Width="426" FontSize="44" FontStyle="Italic" Click="Button_Click_4"/>
<Button Content="Розклад занять" HorizontalAlignment="Left" Height="130" Margin="-10,261,0,0" VerticalAlignment="Top" Width="426" FontSize="44" FontStyle="Italic"/>
<TextBlock HorizontalAlignment="Center" Height="111" Margin="0,10,20,0" TextWrapping="Wrap" Text=" Додатково" VerticalAlignment="Top" Width="406" Foreground="#FFA60998" FontSize="70" FontStyle="Italic" FontFamily="Harlow Solid Italic"/>
<Button Content="Назад" HorizontalAlignment="Left" Height="130" Margin="-10,391,0,0" VerticalAlignment="Top" Width="426" FontSize="44" FontStyle="Italic" Click="Button_Click_3"/>
</Grid>
<TextBox x:Name="text3" HorizontalAlignment="Left" Height="416" Margin="88,50,0,0" Grid.Row="1" TextWrapping="Wrap" Text="0. 8.00-8.55
1. 9.00-10.20
2. 10.30-11.50
3. 12.20-13.40
4. 13.50-15.10
5. 15.30-16.50
6. 17.00-18.20" VerticalAlignment="Top" Width="320" FontSize="36" Background="#FF23F9EF" Visibility="Collapsed"/>
<Button x:Name="button" Content="Назад" HorizontalAlignment="Left" Height="82" Margin="128,471,0,0" Grid.Row="1" VerticalAlignment="Top" Width="244" Click="Button_Click_5" Visibility="Collapsed"/>
<Grid x:Name="control3" HorizontalAlignment="Left" Height="508" Margin="14,146,0,0" VerticalAlignment="Top" Width="456" Grid.RowSpan="2" Visibility="Collapsed">
<Button Content="Понеділок" HorizontalAlignment="Left" Margin="10,31,0,0" VerticalAlignment="Top" Height="84" Width="436" FontFamily="Times New Roman" FontSize="48" FontStyle="Italic" Click="Button_Click_8"/>
<Button Content="Пятниця" HorizontalAlignment="Left" Margin="10,372,0,0" VerticalAlignment="Top" Height="84" Width="436" FontFamily="Times New Roman" FontSize="48" Click="Button_Click_15"/>
<Button Content="Четвер" HorizontalAlignment="Left" Margin="10,288,0,139" Width="436" FontFamily="Times New Roman" FontSize="48" Click="Button_Click_13"/>
<Button Content="Середа" HorizontalAlignment="Left" Margin="10,204,0,0" VerticalAlignment="Top" Height="84" Width="436" FontFamily="Times New Roman" FontSize="48" FontStyle="Italic" Click="Button_Click_11"/>
<Button Content="Вівторок" HorizontalAlignment="Left" Margin="10,115,0,0" VerticalAlignment="Top" Height="84" Width="436" FontFamily="Times New Roman" FontSize="48" FontStyle="Italic" Click="Button_Click_10"/>
<Button Content="Назад" HorizontalAlignment="Left" Height="69" Margin="142,442,0,0" VerticalAlignment="Top" Width="182" Click="Button_Click_6"/>
</Grid>
<TextBlock x:Name="text5" HorizontalAlignment="Left" Height="252" Margin="128,77,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Width="244" FontSize="48" FontFamily="Times New Roman" FontStyle="Italic" TextAlignment="Center" Visibility="Collapsed">
<Run Text="Понеділок" TextDecorations="Underline"/>
<LineBreak/>
<Run TextDecorations="Underline"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="1.ООП"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="2.Компютерна графіка"/>
</TextBlock>
<Button x:Name="button55" Content="Назад" HorizontalAlignment="Left" Margin="187,371,0,0" Grid.Row="1" VerticalAlignment="Top" Width="138" Click="button55_Click" Visibility="Collapsed"/>
<TextBlock x:Name="text6" HorizontalAlignment="Left" Height="291" Margin="128,80,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Width="244" FontSize="48" FontFamily="Times New Roman" FontStyle="Italic" TextAlignment="Center" Visibility="Collapsed">
<Run Text="Вівторок" TextDecorations="Underline"/>
<LineBreak/>
<Run/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="1.ПОП"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="2.Чисельні методи"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="3.ТІМС"/>
</TextBlock>
<Button x:Name="button66" Content="Назад" HorizontalAlignment="Left" Margin="169,394,0,0" Grid.Row="1" VerticalAlignment="Top" Width="156" Click="Button_Click_9" Visibility="Collapsed"/>
<TextBlock x:Name="text7" HorizontalAlignment="Left" Height="457" Margin="88,14,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Width="340" FontFamily="Times New Roman" FontSize="48" FontStyle="Italic" TextAlignment="Center" Visibility="Collapsed">
<Run Text="Середа" TextDecorations="Underline"/>
<LineBreak/>
<Run/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="1.Вікно або консультація до КР"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="2.ООП"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="3.Фізичне виховання"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="4.Системне програмування"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="5.ТІМС"/>
</TextBlock>
<Button x:Name="button77" Content="Назад" HorizontalAlignment="Left" Height="73" Margin="169,421,0,0" Grid.Row="1" VerticalAlignment="Top" Width="174" Click="button77_Click" Visibility="Collapsed"/>
<TextBlock x:Name="text8" HorizontalAlignment="Left" Height="426" Margin="10,14,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="456" FontSize="48" FontFamily="Times New Roman" FontStyle="Italic" TextAlignment="Center" Grid.Row="1" Visibility="Collapsed">
<Run Text="Четвер" TextDecorations="Underline"/>
<LineBreak/>
<Run/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="1.Чисельні методи або оргaнізація баз даних"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="2.Німецька мова"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="3.Компютерна графіка"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="4.Математичні методи дослідження операцій"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="5.Англійська мова"/>
</TextBlock>
<Button x:Name="button88" Content="Назад" HorizontalAlignment="Left" Height="82" Margin="146,434,0,0" Grid.Row="1" VerticalAlignment="Top" Width="197" Click="Button_Click_12" Visibility="Collapsed"/>
<TextBlock x:Name="text9" HorizontalAlignment="Left" Height="316" Margin="84,50,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Width="344" FontSize="48" FontFamily="Times New Roman" FontStyle="Italic" TextAlignment="Center" Visibility="Collapsed">
<Run Text="Пятниця" TextDecorations="Underline"/>
<LineBreak/>
<Run/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="4.Організація баз даних"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="5.Електротехніка"/>
<LineBreak/>
<Run FontStyle="Normal" FontSize="36" Text="6.Соціологія"/>
</TextBlock>
<Button x:Name="button99" Content="Назад" HorizontalAlignment="Left" Height="84" Margin="146,356,0,0" Grid.Row="1" VerticalAlignment="Top" Width="226" Click="Button_Click_14" Visibility="Collapsed"/>
</Grid>
</phone:PhoneApplicationPage> }
2.4.Опис коду
Для розробки додатків під платформу Windows Phone 8.1 потрібно встанови на комп’ютері операційну систему Windows 8.0 або Window 8.1, так як для інших операційних систем немає потрібного візуального середовища програмування. В даному випадку розробка проекту проводиться на ОС Window 8.1. Згодом потрібно встановити необхідне середовище програмування, а саме Visual Studio Express 2013 для Windows Phone.
Програма “Калькулятор”, містить кнопки, текст, поле для виведення результату, різного виду дані та використовує форми, нам необхідно підключити такі бібліотеки:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Сalculator_Prod_Azaza.Resources;
Для присвоєння цифр полю TextBox використовується такий код (Рис. 2.4.1.):
private void Number_Click(object sender, RoutedEventArgs e)
{
Button b = (Button)sender;
TextBox.Text += b.Content.ToString();
}
Рис. 2.4.1. Введення значень
Для обчислення і виведення результату в поле TextBox використовується наступна функція :
private void buttonrezult_Click(object sender, RoutedEventArgs e)
{
String op;
int iop=0;
if (TextBox.Text.Contains("+"))
{
iop = TextBox.Text.IndexOf("+");
}
else if (TextBox.Text.Contains("-"))
{
iop = TextBox.Text.IndexOf("-");
}
if (TextBox.Text.Contains("*"))
{
iop = TextBox.Text.IndexOf("*");
}
if (TextBox.Text.Contains("/"))
{
iop = TextBox.Text.IndexOf("/");
}
else
{
}
op = TextBox.Text.Substring(iop, 1);
double op1 = Convert.ToDouble(TextBox.Text.Substring(0, iop));
double op2 = Convert.ToDouble(TextBox.Text.Substring(iop+1,TextBox.Text.Length - iop-1));
if (op=="+")
{
TextBox.Text += "=" + (op1 + op2);
}
if (op == "-")
{
TextBox.Text += "=" + (op1 - op2);
}
if (op == "*")
{
TextBox.Text += "=" + (op1 * op2);
}
if (op == "/")
{
TextBox.Text += "=" + (op1 / op2);
}
}
Для очистки TextBox треба використати такий код (Рис. 2.4.2.):
private void buttoncc_Click(object sender