0% found this document useful (0 votes)
39 views

Using Using Using Using Using Using Using Using Using Using Using Using Using Using Using Namespace

This document contains the C# code for a basic calculator application with a graphical user interface. It includes code to handle button clicks for the numeric digits and arithmetic operators. When an operator button is clicked, it appends the operator to the screen text. When the equals button is clicked, it tries to evaluate the expression on the screen by splitting it and performing the arithmetic operation. It catches exceptions if the syntax is invalid.

Uploaded by

Nofearmak
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Using Using Using Using Using Using Using Using Using Using Using Using Using Using Using Namespace

This document contains the C# code for a basic calculator application with a graphical user interface. It includes code to handle button clicks for the numeric digits and arithmetic operators. When an operator button is clicked, it appends the operator to the screen text. When the equals button is clicked, it tries to evaluate the expression on the screen by splitting it and performing the arithmetic operation. It catches exceptions if the syntax is invalid.

Uploaded by

Nofearmak
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication10
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

public MainWindow()
{
InitializeComponent();
}

private void zero_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "0";
}

private void point_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + ".";
}

private void Clear_Click(object sender, RoutedEventArgs e)


{
screen.Text = "";
}

private void one_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "1";
}

private void two_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "2";
}

private void three_click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "3";
}

private void four_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "4";
}

private void five_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "5";
}

private void Six_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "6";
}

private void seven_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "7";
}

private void eight_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "8";
}

private void nine_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "9";
}

private void lpar_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "(";
}

private void rpar_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + ")";
}

private void plus_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "+";
//int a = Convert.ToInt32(screen.Text);
// int b = Convert.ToInt32(screen.Text);

//int result = System.Convert.ToInt32(screen.Text) +


System.Convert.ToInt32(screen.Text);
//screen.Text = result.ToString();
}

private void minus_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "-";
// int result = System.Convert.ToInt32(screen.Text) -
System.Convert.ToInt32(screen.Text);
//screen.Text = result.ToString();

private void mul_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "*";
//int result = System.Convert.ToInt32(screen.Text) *
System.Convert.ToInt32(screen.Text);
//screen.Text = result.ToString();
}

private void div_Click(object sender, RoutedEventArgs e)


{
screen.Text = screen.Text + "/";
//int result = System.Convert.ToInt32(screen.Text) /
System.Convert.ToInt32(screen.Text);
//screen.Text = result.ToString();
}
private void back_Click(object sender, RoutedEventArgs e)
{
if (screen.Text != "")
screen.Text = screen.Text.Remove(screen.Text.Length - 1);
}

private void result_Click(object sender, RoutedEventArgs e)


//{
// string FirstNumber = screen.Text + "";
//string mathOperator = screen.Text + "";
//}

//private void AddButton_Click(object sender, EventArgs e)


//{
// FirstNumber = Convert.ToDouble(screen.Text);
//mathOperator = "+";

// screen.Text = "";
// screen.Focus();
//{
// compute(count);
// }
//public void compute(int count)
// {
//
// }
// Double SecondNumber;
//SecondNumber = Convert.ToDouble(screen.Text);

// int result = Int32.Parse(screen.Text) + Int32.Parse(screen.Text);

//screen.Text = result.ToString();
// int result = Int32.Parse(screen.Text) + Int32.Parse(screen.Text);

// int a = Convert.ToInt32(screen.Text);
//int b = Convert.ToInt32(screen.Text);
//Type scriptType = Type.GetTypeFromCLSID(Guid.Parse("0ES9F1D5-1FBE-11D0-8FF2-
00A0D10038BC"));
//dynamic obj = Activator.CreateInstance(scriptType, false);
//obj.Language = "javascript";
{

string[] str = new String[16];


string InputStr = screen.Text;

try
{

str = InputStr.Split('+');
if (str[0].Length == 0)
{
str = InputStr.Split('*');

if (str[0].Length == 0)
{
str = InputStr.Split('-');

if (str[0].Length == 0)
{
str = InputStr.Split('/');
int result = System.Convert.ToInt32(str[0]) /
System.Convert.ToInt32(str[1]);
screen.Text = result.ToString();

}
else
{

int result = System.Convert.ToInt32(str[0]) -


System.Convert.ToInt32(str[1]);
screen.Text = result.ToString();
}
}
else
{

int result = System.Convert.ToInt32(str[0]) *


System.Convert.ToInt32(str[1]);
screen.Text = result.ToString();

}
}
else
{
int result = System.Convert.ToInt32(str[0]) +
System.Convert.ToInt32(str[1]);
screen.Text = result.ToString();
}
//InputStr.Split()
// var res = obj.Eval(screen.Text);
// str = Convert.ToString(res);
// screen.Text = result.ToString();
InputStr = screen.Text;
// str = InputStr.Split('*');
// MessageBox.Show(screen.Text);
// MessageBox.Show(str[0]);
}
catch (Exception ex)
{
screen.Text = "Syntax Error" + ex.Message.ToString();
}
}
}
}

You might also like