private void ValidateTextInput(TextBox textBox, out double sideLength) { // Allow text boxes that are empty or that contain only a single decimal. if (string.IsNullOrEmpty(textBox.Text) || textBox.Text == ".") { sideLength = 0; } // If current input is not a valid number, clear text box and display invalid input error. else if (!double.TryParse(textBox.Text, out sideLength)) { messageText.Text = ERR_INVALID_INPUT; // Temporarily disable events to prevent firing when clearing the text box. DisableTextBoxEvents(); textBox.Clear(); EnableTextBoxEvents(); return; } // If any inputs are blank, display instructions. if (string.IsNullOrEmpty(sideATextBox.Text) || string.IsNullOrEmpty(sideBTextBox.Text) || string.IsNullOrEmpty(sideCTextBox.Text)) { messageText.Text = INSTRUCTIONS; return; } try { var info = TriangleChecker.GetTriangleStats(_sideA, _sideB, _sideC); // Side lenghts make a valid triangle! Display the triangle type. messageText.Text = GetTriangleMessage(info); } catch (ArgumentException) { // One or more side lengths are not valid; display invalid input error. messageText.Text = ERR_INVALID_INPUT; } catch (InvalidTriangleException) { // Side lengths do not make a valid triangle; display invalid triangle error. messageText.Text = ERR_INVALID_TRIANGLE; } }