double Operand1, Operand2, result, value;
string Op;
Boolean clearDisplay;
private void Digit_Click(object sender, EventArgs e)
{
if (clearDisplay)
{
lblDisplay.Text = "";
clearDisplay = false;
}
//namespace display():
Button b = (Button)sender;
lblDisplay.Text = lblDisplay.Text + b.Text;
}
private void btnAdd_Click(object sender, EventArgs e)
{
}
private void GetOperator_Click(object sender, EventArgs e)
{
if (lblDisplay.Text.Length == 0)
{
return;
}
Operand1 = Convert.ToDouble(lblDisplay.Text);
Button b = (Button)sender;
Op = b.Text;
lblDisplay.Text = "";
clearDisplay = true;
}
private void btnEquals_Click(object sender, EventArgs e)
{
if (lblDisplay.Text.Length == 0)
{
return;
}
Operand2 = Convert.ToDouble(lblDisplay.Text);
clearDisplay = true;
switch (Op)
{
case "+":
result = Operand1 + Operand2;
lblDisplay.Text = result.ToString();
break;
case "-":
result = Operand1 - Operand2;
lblDisplay.Text = result.ToString();
break;
case "*":
result = Operand1 * Operand2;
lblDisplay.Text = result.ToString();
break;
case "/":
if (Operand2 != 0)
{
result = Operand1 / Operand2;
lblDisplay.Text = result.ToString();
}
break;
default:
break;
}
}
private void btnClear_Click(object sender, EventArgs e)
{
lblDisplay.Text = "";
}
private void btnBackSpace_Click(object sender, EventArgs e)
{
if (lblDisplay.Text.Length == 0)
{
return;
}
lblDisplay.Text = lblDisplay.Text.Remove(lblDisplay.Text.Length - 1, 1);
}
private void btnInverse_Click(object sender, EventArgs e)
{
if (lblDisplay.Text.Length == 0)
{
return;
}
value = Convert.ToDouble(lblDisplay.Text);
if (value != 0)
{
result = 1 / value;
lblDisplay.Text = result.ToString();
}
}
private void btnSign_Click(object sender, EventArgs e)
{
if (lblDisplay.Text.Length == 0)
{
return;
}
value = Convert.ToDouble(lblDisplay.Text);
result = -1 * value;
lblDisplay.Text = result.ToString();
}
Courtesy : Binish Babu
Wednesday, February 19, 2014
Windows Forms Calculator
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment