using System;
using System.Windows.Forms;
namespace calculator
{
public partial class Calculator : Form
{
public Calculator ()
{
InitializeComponent();
}
char operation;
double a;
////////Button ForNumber0 to Number9 on Number Button
private void buttonForNumber0_Click(object sender, EventArgs e)
{
button6.Text = "0";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button6.Text;
}
else
{
Display.Text = Display.Text + button6.Text;
}
}
private void buttonForNumber1_Click(object sender, EventArgs e)
{
button4.Text = "1";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button4.Text;
}
else
{
Display.Text = Display.Text + button4.Text;
}
}
private void buttonForNumber2_Click(object sender, EventArgs e)
{
button7.Text = "2";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button7.Text;
}
else
{
Display.Text = Display.Text + button7.Text;
}
}
private void buttonForNumber3_Click(object sender, EventArgs e)
{
button12.Text = "3";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button12.Text;
}
else
{
Display.Text = Display.Text + button12.Text;
}
}
private void buttonForNumber4_Click(object sender, EventArgs e)
{
button3.Text = "4";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button3.Text;
}
else
{
Display.Text = Display.Text + button3.Text;
}
}
private void buttonForNumber5_Click(object sender, EventArgs e)
{
button8.Text = "5";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button8.Text;
}
else
{
Display.Text = Display.Text + button8.Text;
}
}
private void buttonForNumber6_Click(object sender, EventArgs e)
{
button13.Text = "6";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button13.Text;
}
else
{
Display.Text = Display.Text + button13.Text;
}
}
private void buttonForNumber7_Click(object sender, EventArgs e)
{
button2.Text = "7";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button2.Text;
}
else
{
Display.Text = Display.Text + button2.Text;
}
}
private void buttonForNumber8_Click(object sender, EventArgs e)
{
button9.Text = "8";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button9.Text;
}
else
{
Display.Text = Display.Text + button9.Text;
}
}
private void buttonForNumber9_Click(object sender, EventArgs e)
{
button14.Text = "9";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button14.Text;
}
else
{
Display.Text = Display.Text + button14.Text;
}
}
///BackSpace Button Coding
private void buttonForBackSpace_Click(object sender, EventArgs e)
{
if ((String.Compare(Display.Text, " ") < 0))
{
Display.Clear();
Display.Text = "0";
}
else
{
Display.Text = Display.Text.Substring(0, Display.Text.Length - 1);
if ((String.Compare(Display.Text, " ") < 0))
{
Display.Text = "0";
}
}
}
/////Button For Decimal Point
private void buttonForDecimal_Click(object sender, EventArgs e)
{
button11.Text = ".";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button11.Text;
}
else
{
Display.Text = Display.Text + button11.Text;
}
}
/////Button For Double Zero 00 Point
private void button5_Click(object sender, EventArgs e)
{
button5.Text = "00";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button5.Text;
}
else
{
Display.Text = Display.Text + button5.Text;
}
////On Addition Button Coding
private void buttonAddition_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(Display.Text);
operation = '+';
Display.Text = "0";
}
////On Subtraction Button Coding
private void buttonSubtraction _Click(object sender, EventArgs e)
{
a = Convert.ToDouble(Display.Text);
operation = '-';
Display.Text = "0";
}
////On Multiplication Button Coding
private void buttonMultiplication _Click(object sender, EventArgs e)
{
a = Convert.ToDouble(Display.Text);
operation = '*';
Display.Text = "0";
}
////On DivisonButton Coding
private void buttonDivison_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(Display.Text);
operation = '/';
Display.Text = "0";
}
////On Remainder Button Coding
private void buttonRemainder _Click(object sender, EventArgs e)
{
a = Convert.ToDouble(Display.Text);
operation = '%';
Display.Text = "0";
}
////On Equal = button coding
private void buttonEqual_Click(object sender, EventArgs e)
{
if (Display.Text == "0")
{
Display.Text = "0";
}
else
{
switch (operation)
{
case ('+'):
double add = Convert.ToDouble(Display.Text);
double addition = Convert.ToDouble(a + add);
Display.Text = Convert.ToString(addition);
break;
case ('-'):
double sub = Convert.ToDouble(Display.Text);
double substraction = Convert.ToDouble(a - sub);
Display.Text = Convert.ToString(substraction);
break;
case ('*'):
double multi = Convert.ToDouble(Display.Text);
double multiplication = Convert.ToDouble(a * multi);
Display.Text = Convert.ToString(multiplication);
break;
case ('/'):
double div = Convert.ToDouble(Display.Text);
double division = Convert.ToDouble(a / div);
Display.Text = Convert.ToString(division);
break;
case ('%'):
double m = Convert.ToDouble(Display.Text);
double mod = Convert.ToDouble(a % m);
Display.Text = Convert.ToString(mod);
break;
}
}
}
}
}
}
using System.Windows.Forms;
namespace calculator
{
public partial class Calculator : Form
{
public Calculator ()
{
InitializeComponent();
}
char operation;
double a;
////////Button ForNumber0 to Number9 on Number Button
private void buttonForNumber0_Click(object sender, EventArgs e)
{
button6.Text = "0";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button6.Text;
}
else
{
Display.Text = Display.Text + button6.Text;
}
}
private void buttonForNumber1_Click(object sender, EventArgs e)
{
button4.Text = "1";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button4.Text;
}
else
{
Display.Text = Display.Text + button4.Text;
}
}
private void buttonForNumber2_Click(object sender, EventArgs e)
{
button7.Text = "2";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button7.Text;
}
else
{
Display.Text = Display.Text + button7.Text;
}
}
private void buttonForNumber3_Click(object sender, EventArgs e)
{
button12.Text = "3";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button12.Text;
}
else
{
Display.Text = Display.Text + button12.Text;
}
}
private void buttonForNumber4_Click(object sender, EventArgs e)
{
button3.Text = "4";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button3.Text;
}
else
{
Display.Text = Display.Text + button3.Text;
}
}
private void buttonForNumber5_Click(object sender, EventArgs e)
{
button8.Text = "5";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button8.Text;
}
else
{
Display.Text = Display.Text + button8.Text;
}
}
private void buttonForNumber6_Click(object sender, EventArgs e)
{
button13.Text = "6";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button13.Text;
}
else
{
Display.Text = Display.Text + button13.Text;
}
}
private void buttonForNumber7_Click(object sender, EventArgs e)
{
button2.Text = "7";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button2.Text;
}
else
{
Display.Text = Display.Text + button2.Text;
}
}
private void buttonForNumber8_Click(object sender, EventArgs e)
{
button9.Text = "8";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button9.Text;
}
else
{
Display.Text = Display.Text + button9.Text;
}
}
private void buttonForNumber9_Click(object sender, EventArgs e)
{
button14.Text = "9";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button14.Text;
}
else
{
Display.Text = Display.Text + button14.Text;
}
}
///BackSpace Button Coding
private void buttonForBackSpace_Click(object sender, EventArgs e)
{
if ((String.Compare(Display.Text, " ") < 0))
{
Display.Clear();
Display.Text = "0";
}
else
{
Display.Text = Display.Text.Substring(0, Display.Text.Length - 1);
if ((String.Compare(Display.Text, " ") < 0))
{
Display.Text = "0";
}
}
}
/////Button For Decimal Point
private void buttonForDecimal_Click(object sender, EventArgs e)
{
button11.Text = ".";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button11.Text;
}
else
{
Display.Text = Display.Text + button11.Text;
}
}
/////Button For Double Zero 00 Point
private void button5_Click(object sender, EventArgs e)
{
button5.Text = "00";
if (Display.Text == "0")
{
Display.Clear();
Display.Text = Display.Text + button5.Text;
}
else
{
Display.Text = Display.Text + button5.Text;
}
private void buttonAddition_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(Display.Text);
operation = '+';
Display.Text = "0";
}
////On Subtraction Button Coding
private void buttonSubtraction _Click(object sender, EventArgs e)
{
a = Convert.ToDouble(Display.Text);
operation = '-';
Display.Text = "0";
}
////On Multiplication Button Coding
private void buttonMultiplication _Click(object sender, EventArgs e)
{
a = Convert.ToDouble(Display.Text);
operation = '*';
Display.Text = "0";
}
////On DivisonButton Coding
private void buttonDivison_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(Display.Text);
operation = '/';
Display.Text = "0";
}
////On Remainder Button Coding
private void buttonRemainder _Click(object sender, EventArgs e)
{
a = Convert.ToDouble(Display.Text);
operation = '%';
Display.Text = "0";
}
////On Equal = button coding
private void buttonEqual_Click(object sender, EventArgs e)
{
if (Display.Text == "0")
{
Display.Text = "0";
}
else
{
switch (operation)
{
case ('+'):
double add = Convert.ToDouble(Display.Text);
double addition = Convert.ToDouble(a + add);
Display.Text = Convert.ToString(addition);
break;
case ('-'):
double sub = Convert.ToDouble(Display.Text);
double substraction = Convert.ToDouble(a - sub);
Display.Text = Convert.ToString(substraction);
break;
case ('*'):
double multi = Convert.ToDouble(Display.Text);
double multiplication = Convert.ToDouble(a * multi);
Display.Text = Convert.ToString(multiplication);
break;
case ('/'):
double div = Convert.ToDouble(Display.Text);
double division = Convert.ToDouble(a / div);
Display.Text = Convert.ToString(division);
break;
case ('%'):
double m = Convert.ToDouble(Display.Text);
double mod = Convert.ToDouble(a % m);
Display.Text = Convert.ToString(mod);
break;
}
}
}
}
}
}
No comments:
Post a Comment