コード例 #1
0
ファイル: Form1.cs プロジェクト: Jasphur/SimpleCalculator
        // Operator toevoegen aan rekensom
        private void OperatorBtn_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            // Checken of er al een eerder som heeft plaats gevonden. Bij true: uitkomst als eerste input getal gebruiken, daarna invoeren orperator
            if (value != 0)
            {
                if (operatorUsed == false)
                {
                    // Onmogelijk maken twee keer klikken op operator toets
                    EqualBtn.PerformClick();
                    operatorUsed = true;
                }

                input        = btn.Text;
                equalBtnUsed = false;
                deciCount    = 0;
            }

            // invoeren operator
            else
            {
                input        = btn.Text;
                value        = Double.Parse(result.Text);
                operatorUsed = true;
                deciCount    = 0;
            }
        }
コード例 #2
0
        private void OperationClick(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            ResultBox.Text = ResultBox.Text.Trim();
            if (ResultBox.Text != "0" && ResultBox.Text != null)
            {
                EqualBtn.PerformClick();
                Text      = button.Text;
                Value     = Double.Parse(ResultBox.Text);
                OperPress = true;
            }
            else
            {
                Text      = button.Text;
                Value     = Double.Parse(ResultBox.Text);
                OperPress = true;
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: tserrante/calculator
        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
        }
コード例 #4
0
        private void Calculate_KeyPress(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar.ToString())
            {
            case "1":
                button1.PerformClick();
                break;

            case "2":
                button2.PerformClick();
                break;

            case "3":
                button3.PerformClick();
                break;

            case "4":
                button4.PerformClick();
                break;

            case "5":
                button5.PerformClick();
                break;

            case "6":
                button6.PerformClick();
                break;

            case "7":
                button7.PerformClick();
                break;

            case "8":
                button8.PerformClick();
                break;

            case "9":
                button9.PerformClick();
                break;

            case "0":
                button0.PerformClick();
                break;

            case "+":
                PlusBtn.PerformClick();
                break;

            case "-":
                SubtractBtn.PerformClick();
                break;

            case "*":
                MultipleBtn.PerformClick();
                break;

            case "/":
                DevideBtn.PerformClick();
                break;

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

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

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

            case "(":
                LeftBracketBtn.PerformClick();
                break;

            case ")":
                RightBracketBtn.PerformClick();
                break;

            case ".":
                PointBtn.PerformClick();
                break;

            case "%":
                Percent.PerformClick();
                break;

            case "\b":
                CEBtn.PerformClick();
                break;

            default: break;
            }
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: Jasphur/SimpleCalculator
        // Zorgen dat het toetsenbord gebruikt kan worden
        private void NumPadInput(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar.ToString())
            {
            case "0":
                ZeroBtn.PerformClick();
                break;

            case "1":
                OneBtn.PerformClick();
                break;

            case "2":
                TwoBtn.PerformClick();
                break;

            case "3":
                ThreeBtn.PerformClick();
                break;

            case "4":
                FourBtn.PerformClick();
                break;

            case "5":
                FiveBtn.PerformClick();
                break;

            case "6":
                SixBtn.PerformClick();
                break;

            case "7":
                SevenBtn.PerformClick();
                break;

            case "8":
                EightBtn.PerformClick();
                break;

            case "9":
                NineBtn.PerformClick();
                break;

            case "*":
                TimesBtn.PerformClick();
                break;

            case "/":
                DivideBtn.PerformClick();
                break;

            case "-":
                SubtractBtn.PerformClick();
                break;

            case "+":
                Addbtn.PerformClick();
                break;

            case ",":
                DecimalBtn.PerformClick();
                break;

            case ".":
                DecimalBtn.PerformClick();
                break;

            case "c":
                ClearBtn.PerformClick();
                break;

            // Twee keer op de "c" toets op het toetsenbord klikken voor een All Clear
            case "c" + "c":
                AllClearBtn.PerformClick();
                break;

            default:
                break;
            }

            // De "Enter" toets op het toetsenbord de functie van de "=" toets toewijzen
            if (e.KeyChar == (char)Keys.Enter)
            {
                EqualBtn.PerformClick();
            }
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: tserrante/calculator
        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
        }