Windows Phone Calculator by Lubomir Marinski

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 PhoneApp3.Resources;

namespace PhoneApp3
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();

// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}

public double z = 0, a = 0, c = 0,s=0,b=0;

private void button1_Click(object sender, RoutedEventArgs e)
{
textBox1.Text += “1”;
}

private void button2_Click(object sender, RoutedEventArgs e)
{
textBox1.Text += “2”;
}

private void button3_Click(object sender, RoutedEventArgs e)
{
textBox1.Text += “3”;
}

private void button4_Click(object sender, RoutedEventArgs e)
{
textBox1.Text += “4”;
}

private void button5_Click(object sender, RoutedEventArgs e)
{
textBox1.Text += “5”;
}
private void button6_Click(object sender, RoutedEventArgs e)
{
textBox1.Text += “6”;
}

private void button7_Click(object sender, RoutedEventArgs e)
{
textBox1.Text += “7”;
}

private void button8_Click(object sender, RoutedEventArgs e)
{
textBox1.Text += “8”;
}

private void button9_Click(object sender, RoutedEventArgs e)
{
textBox1.Text += “9”;
}
// +
private void buttonx_Click(object sender, RoutedEventArgs e)
{
b = double.Parse(textBox1.Text);
c = b;
textBox1.Text = “”;
z = 1;
}
// –
private void buttonx1_Click(object sender, RoutedEventArgs e)
{
b = double.Parse(textBox1.Text);
c = b;
textBox1.Text = “”;
z = 2;
}

private void buttonx2_Click(object sender, RoutedEventArgs e)
{
b = double.Parse(textBox1.Text);
c = b;
textBox1.Text = “”;
z = 3;
}

private void buttonx3_Click(object sender, RoutedEventArgs e)
{
b = double.Parse(textBox1.Text);
c = b;
textBox1.Text = “”;
z = 4;
}

private void buttonz_Click(object sender, RoutedEventArgs e)
{
var p = double.Parse(textBox1.Text);
if (z == 1) s = b + p;
if (z == 2) s = b – p;
if (z == 3) s = b * p;
if (z == 4) s = b / p;
textBox1.Text = System.Convert.ToString(s);
}

private void button0_Click(object sender, RoutedEventArgs e)
{
textBox1.Text += “0”;
}

private void buttonc_Click(object sender, RoutedEventArgs e)
{
textBox1.Text = “”;
}

// Sample code for building a localized ApplicationBar
//private void BuildLocalizedApplicationBar()
//{
//    // Set the page’s ApplicationBar to a new instance of ApplicationBar.
//    ApplicationBar = new ApplicationBar();

//    // Create a new button and set the text value to the localized string from AppResources.
//    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri(“/Assets/AppBar/appbar.add.rest.png”, UriKind.Relative));
//    appBarButton.Text = AppResources.AppBarButtonText;
//    ApplicationBar.Buttons.Add(appBarButton);

//    // Create a new menu item with the localized string from AppResources.
//    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
//    ApplicationBar.MenuItems.Add(appBarMenuItem);
//}
}
}

Published by

Dimitar Minchev

PhD of Informatics