using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private double n1;
private double n2;
private string cal;
private bool inputstatus = true;
private void button1_Click(object sender, EventArgs e)
{
if (inputstatus)
{
textBox1.Text += button1.Text;
}
else
{
textBox1.Text = button1.Text;
inputstatus = true;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (inputstatus)
{
textBox1.Text += button2.Text;
}
else
{
textBox1.Text = button2.Text;
inputstatus = true;
}
}
private void button3_Click(object sender, EventArgs e)
{
if (inputstatus)
{
textBox1.Text += button3.Text;
}
else
{
textBox1.Text = button3.Text;
inputstatus = true;
}
}
private void button4_Click(object sender, EventArgs e)
{
if (inputstatus)
{
textBox1.Text += button4.Text;
}
else
{
textBox1.Text = button4.Text;
inputstatus = true;
}
}
private void button5_Click(object sender, EventArgs e)
{
if (inputstatus)
{
textBox1.Text += button5.Text;
}
else
{
textBox1.Text = button5.Text;
inputstatus = true;
}
}
private void button6_Click(object sender, EventArgs e)
{
if (inputstatus)
{
textBox1.Text += button6.Text;
}
else
{
textBox1.Text = button6.Text;
inputstatus = true;
}
}
private void button7_Click(object sender, EventArgs e)
{
if (inputstatus)
{
textBox1.Text += button7.Text;
}
else
{
textBox1.Text = button7.Text;
inputstatus = true;
}
}
private void button8_Click(object sender, EventArgs e)
{
if (inputstatus)
{
textBox1.Text += button8.Text;
}
else
{
textBox1.Text = button8.Text;
inputstatus = true;
}
}
private void button9_Click(object sender, EventArgs e)
{
if (inputstatus)
{
textBox1.Text += button9.Text;
}
else
{
textBox1.Text = button9.Text;
inputstatus = true;
}
}
private void button10_Click(object sender, EventArgs e)
{
if (inputstatus)
{
textBox1.Text += button10.Text;
}
else
{
textBox1.Text = button10.Text;
inputstatus = true;
}
}
private void button11_Click(object sender, EventArgs e)
{
if (inputstatus)
{
textBox1.Text += button11.Text;
}
else
{
textBox1.Text = button11.Text;
inputstatus = true;
}
}
private void button12_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length != 0)
{
n1 = System.Double.Parse(textBox1.Text);
result();
cal = "+";
}
}
private void button13_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length != 0)
{
n1 = System.Double.Parse(textBox1.Text);
result();
cal = "-";
}
}
private void button14_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length != 0)
{
n1 = System.Double.Parse(textBox1.Text);
result();
cal = "*";
}
}
private void button15_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length != 0)
{
n1 = System.Double.Parse(textBox1.Text);
result();
cal = "/";
}
}
private void button16_Click(object sender, EventArgs e)
{
result();
cal = string.Empty;
}
private void button17_Click(object sender, EventArgs e)
{
textBox1.Text = string.Empty;
n1 = 0;
n2 = 0;
cal = string.Empty;
}
private void result()
{
n2 = System.Double.Parse(textBox1.Text);
switch (cal)
{
case "+":
n1 = n1 + n2;
break;
case "-":
n1 = n1 - n2;
break;
case "*":
n1 = n1 * n2;
break;
case "/":
n1 = n1 / n2;
break;
}
textBox1.Text = n1.ToString();
inputstatus = false;
}
}
}