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 WindowsFormsApplication1
{
public
partial class calculator : Form
{
public
calculator()
{
InitializeComponent();
}
string
var1, var2, op;
private
void btn1_Click(object
sender, EventArgs e)
{
textBox1.Text =
textBox1.Text+((Button)sender).Text;
}
private
void btn2_Click(object
sender, EventArgs e)
{
textBox1.Text = textBox1.Text+((Button)sender).Text;
}
private
void btn3_Click(object
sender, EventArgs e)
{
textBox1.Text =
textBox1.Text + ((Button)sender).Text;
}
private
void btn4_Click(object
sender, EventArgs e)
{
textBox1.Text =
textBox1.Text + ((Button)sender).Text;
}
private
void btn5_Click(object
sender, EventArgs e)
{
textBox1.Text =
textBox1.Text + ((Button)sender).Text;
}
private
void btn6_Click(object
sender, EventArgs e)
{
textBox1.Text =
textBox1.Text + ((Button)sender).Text;
}
private
void btn7_Click(object
sender, EventArgs e)
{
textBox1.Text =
textBox1.Text + ((Button)sender).Text;
}
private
void btn8_Click(object
sender, EventArgs e)
{
textBox1.Text =
textBox1.Text + ((Button)sender).Text;
}
private
void btn9_Click(object
sender, EventArgs e)
{
textBox1.Text =
textBox1.Text + ((Button)sender).Text;
}
private
void btn0_Click(object
sender, EventArgs e)
{
textBox1.Text =
textBox1.Text + ((Button)sender).Text;
}
private
void btnplus_Click(object
sender, EventArgs e)
{
var1 = textBox1.Text;
op = "+";
textBox1.Text = "";
}
private
void btnminus_Click(object
sender, EventArgs e)
{
var1 = textBox1.Text;
op = "-";
textBox1.Text = "";
}
private
void btnmul_Click(object
sender, EventArgs e)
{
var1 = textBox1.Text;
op = "*";
textBox1.Text = "";
}
private
void btndiv_Click(object
sender, EventArgs e)
{
var1 = textBox1.Text;
op = "/";
textBox1.Text = "";
}
private
void btnequal_Click(object
sender, EventArgs e)
{
var2 = textBox1.Text;
if
(op == "+")
{
textBox1.Text = Convert.ToString(decimal.Parse(var1)
+ decimal.Parse(var2));
}
if
(op == "-")
{
textBox1.Text = Convert.ToString(decimal.Parse(var1)
- decimal.Parse(var2));
}
if
(op == "*")
{
textBox1.Text = Convert.ToString(decimal.Parse(var1)
* decimal.Parse(var2));
}
if
(op == "/")
{
textBox1.Text = Convert.ToString(decimal.Parse(var1)
/ decimal.Parse(var2));
}
}
private
void btnac_Click(object
sender, EventArgs e)
{
textBox1.Text = "";
var1 = "0";
var2 = "0";
}
}
}
No comments:
Post a Comment