/// <summary> /// Performs the deferred final checks. Shows the error message, plays the beep sound and focuses the control if errors were found. /// </summary> /// <returns>true if the check is successful, false if errors were found</returns> public bool FinalCheck() { bool accept = true; HideErrorNotice(); if (accept && requireInput && Text.Length == 0) { accept = false; } if (accept && finalRegex != null) { accept = finalRegex.IsMatch(Text); } if (accept && FinalValidateText != null) { var e2 = new ValidatingTextBoxEventArgs(Text); FinalValidateText(this, e2); accept = e2.Accept; Text = e2.Text; } if (!accept) { ShowErrorNotice(); SystemSounds.Beep.Play(); Console.Beep(50, 10); Focus(); } return(accept); }
protected override void OnTextChanged(EventArgs e) { bool accept = true; HideErrorNotice(); if (type == ValidatingTextBoxType.Numeric) { string valid = "0123456789"; foreach (char c in Text) { if (valid.IndexOf(c) == -1) { accept = false; break; } } } else if (type == ValidatingTextBoxType.ValidCharacters && !string.IsNullOrEmpty(validCharacters)) { foreach (char c in Text) { if (validCharacters.IndexOf(c) == -1) { accept = false; break; } } } else if (type == ValidatingTextBoxType.RegularExpression && regex != null) { accept = regex.IsMatch(Text); } else if (type == ValidatingTextBoxType.Custom && ValidateText != null) { var e2 = new ValidatingTextBoxEventArgs(Text); ValidateText(this, e2); accept = e2.Accept; } if (!accept) { SystemSounds.Beep.Play(); Console.Beep(50, 10); Text = prevText; SelectionStart = prevSelStart; SelectionLength = prevSelLen; ShowErrorNotice(); } else { prevText = Text; } base.OnTextChanged(e); UpdateAutoHeight(); }