using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SimpeCalculator
{
public partial class Form1 : Form
{
Double result = 0;
String operation = "";
bool isOperationPerformed = false;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if ((textBox_resut.Text == "0") || (isOperationPerformed))
textBox_resut.Clear();
isOperationPerformed = false;
Button button = (Button)sender;
if (button.Text == ".")
{
if(!textBox_resut.Text.Contains("."))
textBox_resut.Text += button.Text;
}
else
textBox_resut.Text += button.Text;
}
private void Operator_click(object sender, EventArgs e)
{
Button button = (Button)sender;
if(result != 0)
{
button5.PerformClick();
operation = button.Text;
labelCurrentOperation.Text = result + " " + operation;
isOperationPerformed = true;
}
else
{
operation = button.Text;
result = Double.Parse(textBox_resut.Text);
labelCurrentOperation.Text = result + " " + operation;
isOperationPerformed = true;
}
}
private void button16_Click(object sender, EventArgs e)
{
textBox_resut.Text = "0";
}
private void button11_Click(object sender, EventArgs e)
{
textBox_resut.Text = "0";
result = 0;
}
private void button5_Click(object sender, EventArgs e)
{
switch (operation)
{
case "+":
textBox_resut.Text = (result + Double.Parse(textBox_resut.Text)).ToString();
break;
case "-":
textBox_resut.Text = (result - Double.Parse(textBox_resut.Text)).ToString();
break;
case "*":
textBox_resut.Text = (result * Double.Parse(textBox_resut.Text)).ToString();
break;
case "/":
textBox_resut.Text = (result / Double.Parse(textBox_resut.Text)).ToString();
break;
default:
break;
}
result = Double.Parse(textBox_resut.Text);
labelCurrentOperation.Text = "";
}
private void labelCurrentOperation_Click(object sender, EventArgs e)
{
}
}
}