Changing the Color of a Single Character In a TextArea string

I need to highlight a single character in a desktoptextarea string depending on where the cursor is in a canvas. I thought it would be easy to make all the characters the same color (green) then make the selected one (As indicated by the variable SelectedPeptideIndex) black, and put that code in the MouseMove handler of the canvas. Nope. The correct character gets a grayish surround, but only the next to last character ever changes color. And the text area blinks incessantly.

For I = 1 To Len( MutatingPeptideTextArea.Text )
MutatingPeptideTextArea.TextColor = RGB( 0 , 210 , 0 )
If Mutations.SelectedPeptideIndex = I - 1 Then
MutatingPeptideTextArea.SelectionStart = Mutations.SelectedPeptideIndex - 1
MutatingPeptideTextArea.SelectionLength = 1
MutatingPeptideTextArea.SelectionTextColor = RGB( 0 , 0 , 0 )
End if
Next

Any suggestions would be welcome.

Set the textarea color before you start your for next loop, not inside it.

For I = 1 To Len( MutatingPeptideTextArea.Text )
//This line is your problem.  It sets all the text to this color every time it iterates through the loop
MutatingPeptideTextArea.TextColor = RGB( 0 , 210 , 0 )
//move the above line outside your loop. Set the textarea color, then run your for next loop
If Mutations.SelectedPeptideIndex = I - 1 Then
MutatingPeptideTextArea.SelectionStart = Mutations.SelectedPeptideIndex - 1
MutatingPeptideTextArea.SelectionLength = 1
MutatingPeptideTextArea.SelectionTextColor = RGB( 0 , 0 , 0 )
End if
Next

If I understand your question correctly, there’s no need to loop. Just put this:

MutatingPeptideTextArea.TextColor=Color.RGB(0,210,0) 'Set all to green
MutatingPeptideTextArea.SelectionStart=Mutations.SelectedPeptideIndex - 1
MutatingPeptideTextArea.SelectionLength=1
MutatingPeptideTextArea.SelectionTextColor=Color.Black

And you can even improve by not selecting the character:

MutatingPeptideTextArea.TextColor=Color.RGB(0,210,0) 'Set all to green
MutatingPeptideTextArea.StyledText.TextColor(Mutations.SelectedPeptideIndex - 1,1)=Color.Black 'Set the character to black.

Yes. Both work a treat. Thank you Mark and Arnaud.