Пример #1
0
        private void MainDisplay_TextChanged(object sender, EventArgs e)
        {
            //Limit input length to 60 character.
            int maxLength = 60;

            if (mainDisplay.Text.Length >= maxLength)
            {
                mainDisplay.Text = mainDisplay.Text.Remove(maxLength - 1, 1) + "";
            }

            //Try and pre-calculate their current expression, if the user were to press equals, but not after they have already pressed equals
            if (mainDisplay.Text.Contains('=') == false)
            {
                //Only calculate if the last term in their expression was fully entered. I.e. not '4 +  ."
                string expression = mainDisplay.Text;
                if (expression.LastIndexOf('.') == expression.Length - 1)
                {
                    return; //Do not calculate an incomplete expression
                }
                else
                {
                    calculator.Start(expression, true);
                }
            }
        }