C#'s Calulator Code
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();
}
bool plus, minus, mul, div, equal= false;
private void button12_Click(object sender, EventArgs e)
{
equal = true;
if (plus)
{
decimal dec = Convert.ToDecimal(txtboxscr.Tag) + Convert.ToDecimal(txtboxscr.Text);
txtboxscr.Text = Convert.ToString(dec);
plus = false;
}
if (minus)
{
decimal dec = Convert.ToDecimal(txtboxscr.Tag) - Convert.ToDecimal(txtboxscr.Text);
txtboxscr.Text = Convert.ToString(dec);
minus = false;
}
if (mul)
{
decimal dec = Convert.ToDecimal(txtboxscr.Tag) * Convert.ToDecimal(txtboxscr.Text);
txtboxscr.Text = Convert.ToString(dec);
mul = false;
}
if (div)
{
decimal dec = Convert.ToDecimal(txtboxscr.Tag) / Convert.ToDecimal(txtboxscr.Text);
txtboxscr.Text = Convert.ToString(dec);
div = false;
}
}
private void button15_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = txtboxscr.Text + "0";
}
private void btn1_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = txtboxscr.Text + "1";
}
private void btn2_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = txtboxscr.Text + "2";
}
private void btn3_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = txtboxscr.Text + "3";
}
private void btn4_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = txtboxscr.Text + "4";
}
private void btn5_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = txtboxscr.Text + "5";
}
private void btn6_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = txtboxscr.Text + "6";
}
private void btn7_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = txtboxscr.Text + "7";
}
private void btn8_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = txtboxscr.Text + "8";
}
private void btn9_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = txtboxscr.Text + "9";
}
private void btnbckspc_Click(object sender, EventArgs e)
{
if (txtboxscr.Text == "")
{
return;
}
else
{
int len = txtboxscr.Text.Length;
txtboxscr.Text = txtboxscr.Text.Remove(len - 1, 1);
}
}
private void btndec_Click(object sender, EventArgs e)
{
CheckifEqual();
if(txtboxscr.Text.Contains("."))
{
return;
}
else
{
txtboxscr.Text = txtboxscr.Text + ".";
}
}
private void btnsgn_Click(object sender, EventArgs e)
{
if (txtboxscr.Text.Contains("-"))
{
txtboxscr.Text = txtboxscr.Text.Remove(0, 1);
}
else
{
txtboxscr.Text = "-" + txtboxscr.Text;
}
}
private void btnadd_Click(object sender, EventArgs e)
{
plus = true;
txtboxscr.Tag = txtboxscr.Text;
txtboxscr.Text = "";
}
private void btnsub_Click(object sender, EventArgs e)
{
minus = true;
txtboxscr.Tag = txtboxscr.Text;
txtboxscr.Text = "";
}
private void btnmul_Click(object sender, EventArgs e)
{
mul = true;
txtboxscr.Tag = txtboxscr.Text;
txtboxscr.Text = "";
}
private void btndiv_Click(object sender, EventArgs e)
{
div = true;
txtboxscr.Tag = txtboxscr.Text;
txtboxscr.Text = "";
}
private void btnc_Click(object sender, EventArgs e)
{
txtboxscr.Text = "";
}
private void btnce_Click(object sender, EventArgs e)
{
txtboxscr.Text = "";
txtboxscr.Tag = "";
plus = false;
minus = false;
div = false;
mul = false;
}
private void btnrot_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = Convert.ToString(Math.Sqrt(Convert.ToDouble(txtboxscr.Text)));
equal = true;
}
private void CheckifEqual()
{
if (equal)
{
txtboxscr.Text = "";
equal = false;
}
}
private void btnfrc_Click(object sender, EventArgs e)
{
CheckifEqual();
txtboxscr.Text = Convert.ToString(1/(Convert.ToDecimal(txtboxscr.Text)));
equal = true;
}
private void btnmr_Click(object sender, EventArgs e)
{
}
}
}
Comments
Post a Comment