Exemple #1
0
        private void AllBtn_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

            // MessageBox.Show(btn.Name); Testing if the buttons have proper name and are used as senders properly
            switch (btn.Name)
            {
            case "BtnDel":
                if (Display.Text.Length > 0)
                {
                    Display.Text = Display.Text.Substring(0, Display.Text.Length - 1); //Will delete one character from display
                }
                break;

            case "BtnC":     //Will clear op and display C = clear
                op = "";
                Display.ResetText();
                Display2.ResetText();
                break;

            case "BtnCE":     //Will clear display CE = Clear Entry
                Display.ResetText();
                break;

            case "BtnPoint":                     //Decimal
                if (!Display.Text.Contains(".")) //case there already is
                {
                    Display.Text += ".";
                }
                break;

            case "BtnNegate":
                if (Display.Text.Length > 0)
                {
                    if (!Display.Text.Contains("-"))   //if it's positive it will a minus at end
                    {
                        Display.Text = "-" + Display.Text;
                    }
                    else if (Display.Text.Contains("-"))   //if it's negative will remove the minus
                    {
                        Display.Text = Display.Text.Substring(1, Display.Text.Length - 1);
                    }
                }
                break;

            default:
                if (op == "=")
                {
                    op = "";
                    Display.ResetText();
                }
                Display.Text += btn.Text;     // adds stuff on display
                break;
            }
        }
Exemple #2
0
        private void Operation_Click(object sender, EventArgs e)
        {
            Button opr = sender as Button;

            switch (opr.Text)
            {
            case "+":
                if (Display.Text.Length > 0)
                {
                    if (op == "" || op == "=")
                    {
                        op            = "+";
                        prevop        = op;
                        preveq        = Display.Text;
                        Display2.Text = preveq + op;
                        Display.ResetText();
                    }
                }
                else
                {
                    op = "+";
                    multi_eq(); //this will do the actual calculations
                }
                break;

            case "-":
                if (Display.Text.Length > 0)
                {
                    if (op == "" || op == "=")
                    {
                        op            = "-";
                        prevop        = op;
                        preveq        = Display.Text;
                        Display2.Text = preveq + op;
                        Display.ResetText();
                    }
                }
                else
                {
                    op = "-";
                    multi_eq();
                }
                break;

            case "÷":
                if (Display.Text.Length > 0)
                {
                    if (op == "" || op == "=")
                    {
                        op            = "÷";
                        prevop        = op;
                        preveq        = Display.Text;
                        Display2.Text = preveq + op;
                        Display.ResetText();
                    }
                }
                else
                {
                    op = "";
                    multi_eq();
                }
                break;

            case "x":
                if (Display.Text.Length > 0)
                {
                    if (op == "" || op == "=")
                    {
                        op            = "x";
                        prevop        = op;
                        preveq        = Display.Text;
                        Display2.Text = preveq + op;
                        Display.ResetText();
                    }
                }
                else
                {
                    op = "x";
                    multi_eq();
                }
                break;

            case "=":
                if (Display.Text.Length > 0)
                {
                    op = "";
                    multi_eq();
                    Display2.ResetText();
                    Display.Text = answer.ToString();
                }
                break;
            }
        }