Exemplo n.º 1
0
        private void Button_Click(object sender, EventArgs e)
        {
            Button b = (Button)sender;

            // remove any leading zeroes
            if (result.Text == "0" || operation_pressed || equals_pressed)
            {
                result.Clear();
            }

            equals_pressed    = false;
            operation_pressed = false;

            if (b.Text == ".")
            {
                if (!result.Text.Contains("."))
                {
                    result.Text += b.Text;
                }
            }
            else
            {
                result.Text += b.Text;
            }

            GrabFocus.Focus(); // switches focus to a hidden label. required for \r to keypress equals
        }
Exemplo n.º 2
0
 private void Clear_click(object sender, EventArgs e)
 {
     result.Clear();
     result.Text   = "0";
     equation.Text = "";
     value         = 0;
     GrabFocus.Focus(); // switches focus to a hidden label. required for \r to keypress equals
 }
Exemplo n.º 3
0
        private void Negate_Click(object sender, EventArgs e)
        {
            if (Double.Parse(result.Text) > 0.0)
            {
                result.Text = '-' + result.Text;
            }
            else if (Double.Parse(result.Text) < 0.0)
            {
                result.Text = result.Text.Remove(0, 1);
            }

            GrabFocus.Focus(); // switches focus to a hidden label. required for \r to keypress equals
        }
Exemplo n.º 4
0
        private void Del_click(object sender, EventArgs e)
        {
            if (result.Text.Length != 1 && result.Text != "0")
            {
                result.Text = result.Text.Remove(result.Text.Length - 1);
            }
            else
            {
                result.Text = "0";
            }

            GrabFocus.Focus(); // switches focus to a hidden label. required for \r to keypress equals
        }
Exemplo n.º 5
0
        private void Operator_click(object sender, EventArgs e)
        {
            Button b = (Button)sender;

            if (value != 0)
            {
                // fire the equals_Click method
                EqualBtn.PerformClick();
                operation_pressed = true;
                operation         = b.Text;
                equation.Text     = value + " " + operation;
            }
            else
            {
                operation = b.Text;
                // since value is a double
                value             = Double.Parse(result.Text);
                operation_pressed = true;
                equation.Text     = value + " " + operation;
            }
            GrabFocus.Focus(); // switches focus to a hidden label. required for \r to keypress equals
        }
Exemplo n.º 6
0
        private void Equals_Click(object sender, EventArgs e)
        {
            equation.Text = "";
            switch (operation)
            {
            case " ":
                EqualBtn.PerformClick();
                break;

            case "\r":
                EqualBtn.PerformClick();
                break;

            case "=":
                EqualBtn.PerformClick();
                break;

            case "+":
                result.Text = Operators.Add(value, Double.Parse(result.Text)).ToString();
                break;

            case "-":
                result.Text = Operators.Sub(value, Double.Parse(result.Text)).ToString();
                break;

            case "*":
                result.Text = Operators.Mult(value, Double.Parse(result.Text)).ToString();
                break;

            case "/":
                if (result.Text == "0")
                {
                    result.Text = "Cannot Divide by Zero";
                }
                else
                {
                    result.Text = Operators.Div(value, Double.Parse(result.Text)).ToString();
                }
                break;

            case "x^n":
                result.Text = Operators.XtoN(value, Double.Parse(result.Text)).ToString();
                break;

            case "Sq":
                result.Text = Operators.Sq(value).ToString();
                break;

            case "sqrt":
                result.Text = Operators.Sqrt(value).ToString();
                break;

            case "nrt":
                result.Text = Operators.NthRT(value, Double.Parse(result.Text)).ToString();
                break;

            default:
                break;
            }//end switch
            equals_pressed = true;

            if (result.Text == ".")
            {
                value = Double.Parse("0.0"); // does not print but this does avoid an exception
            }
            else
            {
                value = Double.Parse(result.Text);
            }


            operation = "";
            GrabFocus.Focus(); // switches focus to a hidden label. required for \r to keypress equals
        }
Exemplo n.º 7
0
 private void ClearEntry_Click(object sender, EventArgs e)
 {
     result.Text = "0";
     GrabFocus.Focus(); // switches focus to a hidden label. required for \r to keypress equals
 }