/// <summary> /// Method to handle the enter key being pressed. /// Calculates the total and then moves the curser to the right hand side of box /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void enterKeyPress(object sender, KeyEventArgs e) { String value; if (e.Key == Key.Enter && MathFunctions.checkLength(calcDisplayBox.Text, out value)) { calcDisplayBox.Text = MathFunctions.calculateTotal(value); } else if (MathFunctions.checkLength(calcDisplayBox.Text, out value)) { calcDisplayBox.Text = value; } calcDisplayBox.Select(calcDisplayBox.Text.Length, 0); }
/// <summary> /// Add a standard operator to the text box. /// Before adding operator calculate the total so it is sequential /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void operatorButtonClick(object sender, RoutedEventArgs e) { calcDisplayBox.Text = MathFunctions.calculateTotal(calcDisplayBox.Text); String value; if (MathFunctions.checkLength(calcDisplayBox.Text, out value)) { calcDisplayBox.Select(calcDisplayBox.Text.Length, 0); calcDisplayBox.Text += ((Button)sender).Content; } else { calcDisplayBox.Text = value; } }