0

I've been trying to color some words in my textbox like "hi", "bye"

I've tried stuff like:

int stIndex = 0;
stIndex = richTextBox1.Find(wh, stIndex, RichTextBoxFinds.MatchCase);
while (stIndex != -1)
{
    if (richTextBox1.SelectedText == wh)
    {
        richTextBox1.SelectionLength = wh.Length;
        richTextBox1.SelectionColor = Color.Blue;
    }
    stIndex = richTextBox1.Find(wh, stIndex + 1, RichTextBoxFinds.MatchCase);
}

but that selects the words thus moving the cursor is there any other way to do this?

Jason Evans
  • 28,906
  • 14
  • 90
  • 154
  • Why set `stIndex` to 0, then immediately change the value? Use `int stIndex = richTextBox1.Find(wh, 0, RichTextBoxFinds.MatchCase)` – John Saunders Mar 21 '14 at 16:05
  • Try looking at [this SO question](http://stackoverflow.com/questions/12150634/c-changing-font-style-of-winform-richtextbox-without-selecting-the-text) and [this one too](http://stackoverflow.com/questions/11186154/rich-text-box-how-to-highlight-text-block-without-select) – Icemanind Mar 21 '14 at 16:07

0 Answers0