MSFanboy
asked on
Handling colorized Text in RichTextBox is buggy moving back with the cursor
Hello,
if the user enters a filter string in my RichTextBox I want the string OR + AND to be colorized.
Below code works until the user goes back with the cursor in order to delete/change code. Then some chars after the cursor gets automatically selected and overwritten, what I do not want. How to change this behaviour, any idea?
if the user enters a filter string in my RichTextBox I want the string OR + AND to be colorized.
Below code works until the user goes back with the cursor in order to delete/change code. Then some chars after the cursor gets automatically selected and overwritten, what I do not want. How to change this behaviour, any idea?
public Regex keyWords = new Regex("AND|OR");
private void rowfilterRichTextBox_TextChanged(object sender, EventArgs e)
{
int selPos = rowfilterRichTextBox.SelectionStart;
foreach (Match keyWordMatch in keyWords.Matches(rowfilterRichTextBox.Text))
{
rowfilterRichTextBox.Select(keyWordMatch.Index, keyWordMatch.Length);
rowfilterRichTextBox.SelectionColor = Color.Blue;
rowfilterRichTextBox.SelectionStart = selPos;
rowfilterRichTextBox.SelectionColor = Color.Black;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.