You are only adding the colour to the actual word that is found in the text box. You need to set the length field based on the index position where the cursor is. Change the first line of the
while
loop in the
CheckKeyword
method to the following:
this.richTextBox1.Select((index), selectStart - index - 1);
Note that as soon as you select any further characters in the line it will change the colouring, so you may need to keep a flag or counter to check how many times it is being changed.