private void Box2_KeyPress(object sender, KeyPressEventArgs e) { //Only Accept a ':', a '-', a numeral, a - f / A - F, or backspace if (IsValidChar(e.KeyChar) || e.KeyChar.ToString() == ":" || e.KeyChar.ToString() == "-" || Char.IsDigit(e.KeyChar) || e.KeyChar == 8) { //If the key pressed is a ':' or '-' if (e.KeyChar.ToString() == ":" || e.KeyChar.ToString() == "-") { //If the Text is valid move to the next box if (Box2.Text != "" && Box2.Text.Length != Box2.SelectionLength) { Box3.Focus(); } e.Handled = true; } //If we are not overwriting the whole text else if (Box2.SelectionLength != Box2.Text.Length) { //Check that the new Text value will be valid // then move on to next box if (Box2.Text.Length == 1) { if (e.KeyChar != 8) { KeyPressBuffer.KeyChar = e.KeyChar; Box3.Focus(); } } } } //Do nothing if the keypress is not a hex value, backspace, '-', or ':' else { e.Handled = true; } }