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();
}
float num1, ans;
int count;
//int result;
ServiceReference1.CalculatorClient obj = new ServiceReference1.CalculatorClient();
private void btnDivide_Click(object sender, EventArgs e) {
num1 = int.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 4;
}
private void btnC_Click(object sender, EventArgs e) {
textBox1.Clear();
count = 0;
}
private void btnCE_Click(object sender, EventArgs e) {
if (num1 == 0 && textBox1.TextLength > 0) {
num1 = 0;
textBox1.Clear();
} else if (num1 > 0 && textBox1.TextLength > 0) {
textBox1.Clear();
}
}
private void btnDelete_Click(object sender, EventArgs e) {
int length = textBox1.TextLength - 1;
string text = textBox1.Text;
textBox1.Clear();
for (int i = 0; i < length; i++) {
textBox1.Text = textBox1.Text + text[i];
}
}
private void btnminus_Click(object sender, EventArgs e) {
if (textBox1.Text != "") {
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 1;
}
}
private void btn1_Click(object sender, EventArgs e) {
textBox1.Text = textBox1.Text + 1;
}
private void btn2_Click(object sender, EventArgs e) {
textBox1.Text = textBox1.Text + 2;
}
private void btn3_Click(object sender, EventArgs e) {
textBox1.Text = textBox1.Text + 3;
}
private void btn4_Click(object sender, EventArgs e) {
textBox1.Text = textBox1.Text + 4;
}
private void btn5_Click(object sender, EventArgs e) {
textBox1.Text = textBox1.Text + 5;
}
private void btn6_Click(object sender, EventArgs e) {
textBox1.Text = textBox1.Text + 6;
}
private void btn7_Click(object sender, EventArgs e) {
textBox1.Text = textBox1.Text + 7;
}
private void btn8_Click(object sender, EventArgs e) {
textBox1.Text = textBox1.Text + 8;
}
private void btn9_Click(object sender, EventArgs e) {
textBox1.Text = textBox1.Text + 9;
}
private void btnMultiply_Click(object sender, EventArgs e) {
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 3;
}
private void btn0_Click(object sender, EventArgs e) {
textBox1.Text = textBox1.Text + 0;
}
private void btnPeriod_Click(object sender, EventArgs e) {
int c = textBox1.TextLength;
int flag = 0;
string text = textBox1.Text;
for (int i = 0; i < c; i++) {
if (text[i].ToString() == ".") {
flag = 1;
break;
} else {
flag = 0;
}
}
if (flag == 0) {
textBox1.Text = textBox1.Text + ".";
}
}
private void btnEqual_Click(object sender, EventArgs e) {
compute(count);
}
private void compute(int count) {
switch (count) {
case 1:
ans = num1 - float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 2:
ans = num1 + float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 3:
ans = num1 * float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 4:
ans = num1 / float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
default:
break;
}
}
private void btnAdd_Click(object sender, EventArgs e) {
num1 = float.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 2;
}
}
}This code snippet is for calculator added all fuctionalties on real calculator. it is colorfull calculator. its every fuction fire in diffrent-2 event.