For example I only the second character in each line to be an x, while the 3nd to 10th character must be a hex digit. At the moment I use a Select Case, then check the position of the caret (using textbox.selectionstart) and see if the key being pressed is a "legal" character.
Is there a better way of doing this as it slows down on large amounts of text.
This is the code I have at the moment:
Select Case TextBox1.SelectionStart
Case TextBox1.GetFirstCharIndexOfCurrentLine + 1
If Not e.KeyChar = "x" Then
e.Handled = True
End If
Case (TextBox1.GetFirstCharIndexOfCurrentLine + 2) To (TextBox1.GetFirstCharIndexOfCurrentLine + 9)
Dim allowedchars As String = "abcdefABCDEF0123456789" & vbCrLf & Chr(Keys.Back)
If allowedchars.Contains(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Select