private void Box1_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 (Box1.Text != "" && Box1.Text.Length != Box1.SelectionLength) { Box2.Focus(); } e.Handled = true; } //If we are not overwriting the whole text else if (Box1.SelectionLength != Box1.Text.Length) { //Check that the new Text value will be valid // then move on to next box if (Box1.Text.Length == 1) { if (e.KeyChar != 8) { KeyPressBuffer.KeyChar = e.KeyChar; Box2.Focus(); } } } } //Do nothing if the keypress is not a hex value, backspace, '-', or ':' else { e.Handled = true; } }