// .NET Program For Calculator.......................................
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 calc : Form
{
public calc()
{
InitializeComponent();
}
private void btnone_Click(object sender, EventArgs e)
{
txtdisplay.Text = txtdisplay.Text + btnone.Text;
}
private void btntwo_Click(object sender, EventArgs e)
{
txtdisplay.Text = txtdisplay.Text + btntwo.Text;
}
private void btnthree_Click(object sender, EventArgs e)
{
txtdisplay.Text = txtdisplay.Text + btnthree.Text;
}
private void btnfour_Click(object sender, EventArgs e)
{
txtdisplay.Text = txtdisplay.Text + btnfour.Text;
}
private void btnfive_Click(object sender, EventArgs e)
{
txtdisplay.Text = txtdisplay.Text + btnfive.Text;
}
private void btnsix_Click(object sender, EventArgs e)
{
txtdisplay.Text = txtdisplay.Text + btnsix.Text;
}
private void btnseven_Click(object sender, EventArgs e)
{
txtdisplay.Text = txtdisplay.Text + btnseven.Text;
}
private void btneight_Click(object sender, EventArgs e)
{
txtdisplay.Text = txtdisplay.Text + btneight.Text;
}
private void btnnine_Click(object sender, EventArgs e)
{
txtdisplay.Text = txtdisplay.Text + btnnine.Text;
}
private void btnten_Click(object sender, EventArgs e)
{
txtdisplay.Text = txtdisplay.Text + btnten.Text;
}
double total = 0;
bool pls = false;
private void btnpls_Click(object sender, EventArgs e)
{
total = double.Parse(txtdisplay.Text);
txtdisplay.Text = "";
pls = true;
dot = false;
}
bool mins = false;
private void btnminus_Click(object sender, EventArgs e)
{
total = double.Parse(txtdisplay.Text);
txtdisplay.Text = "";
mins = true;
dot = false;
}
bool mul = false;
private void btnmul_Click(object sender, EventArgs e)
{
total = double.Parse(txtdisplay.Text);
txtdisplay.Text = "";
mul = true;
dot = false;
}
bool div = false;
private void btndiv_Click(object sender, EventArgs e)
{
total = double.Parse(txtdisplay.Text);
txtdisplay.Text = "";
div = true;
dot = false;
}
double total2 = 0;
private void btnequl_Click(object sender, EventArgs e)
{
if (pls == true)
{
total2 = total + double.Parse(txtdisplay.Text);
txtdisplay.Text = total2.ToString();
total = 0;
pls = false;
}
if (mins == true)
{
total2 = total - double.Parse(txtdisplay.Text);
txtdisplay.Text = total2.ToString();
total = 0;
mins = false;
}
if (div == true)
{
total2 = total / double.Parse(txtdisplay.Text);
txtdisplay.Text = total2.ToString();
total = 0;
div = false;
}
if (mul == true)
{
total2 = total * double.Parse(txtdisplay.Text);
txtdisplay.Text = total2.ToString();
total = 0;
mul = false;
}
}
private void btnbcs_Click(object sender, EventArgs e)
{
if (txtdisplay.Text.Length > 0)
{
txtdisplay.Text = txtdisplay.Text.Remove(txtdisplay.Text.Length - 1);
}
}
private void btnoff_Click(object sender, EventArgs e)
{
this.Close();
}
double m = 0;
private void btnmpls_Click(object sender, EventArgs e)
{
m = double.Parse(txtdisplay.Text);
txtdisplay.Text = "";
}
private void btnmr_Click(object sender, EventArgs e)
{
if (m > 0)
{
txtdisplay.Text = m.ToString();
}
}
private void btnmc_Click(object sender, EventArgs e)
{
m = 0;
}
private void btnclr_Click(object sender, EventArgs e)
{
txtdisplay.Clear();
}
bool dot = false;
private void btndot_Click(object sender, EventArgs e)
{
if (dot == false)
{
txtdisplay.Text = txtdisplay.Text + btndot.Text;
dot = true;
}
}
private void btnsqrt_Click(object sender, EventArgs e)
{
double n = double.Parse(txtdisplay.Text);
double re = Math.Sqrt(n);
txtdisplay.Text = "" +re;
}
private void calc_Load(object sender, EventArgs e)
{
}
}
}
0 comments:
Post a Comment