//Validate Depth Values using Keypress private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { if (Char.IsControl(e.KeyChar) == false && Char.IsDigit(e.KeyChar) == false) { MessageBox.Show("Please enter a number"); e.Handled = true; DepthField.BackColor = Color.Red; DepthField.Focus(); } else { DepthField.BackColor = System.Drawing.SystemColors.Window; } }
//Validate Depth Values using Constraint private void textBox3_Validating(object sender, CancelEventArgs e) { if (int.TryParse(DepthField.Text, out int DepthInput) == true) { if (DepthInput < Desk.MINDEPTH || DepthInput > Desk.MAXDEPTH) { MessageBox.Show("Please enter a depth from " + Desk.MINDEPTH + " to " + Desk.MAXDEPTH + " inches"); DepthField.Text = String.Empty; DepthField.BackColor = Color.Red; DepthField.Focus(); } else { DepthField.BackColor = System.Drawing.SystemColors.Window; } } }