RichTextBox and Find

  • Thread starter Thread starter Steve Barnett
  • Start date Start date
S

Steve Barnett

I have a rich text box that I'm trying to search for information. I want to
be able to search from the end of the text towards the start, so my first
Find method looks like:

RTBedit.Find(TextToFind, RTBedit.Text.Length, RichTextBoxFinds.Reverse);

This finds the last occurrence of TextToFind in the rich text box perfectly
well. I then want to go on to find the next occurrence towards the start of
the text, so I code:

RTBedit.Find(TextToFind, RTBedit.SelectionStart - 1,
RichTextBoxFinds.Reverse);

What I expected to see was the next occurrence highlighted. However, this
code ALWAYS highlights the same occurrence as the first find. It's not
searching backwards at all.It looks like RichTextBoxFinds.Reverse always
starts from the end of the rich text box.

Have I misinterpreted something here? I thought the RichTextBoxFinds.Reverse
was supposed to search backwards from the start position.

Any suggestions.

Thanks
Steve
 
How painfully logical.

Thanks, it's working fine now and so much more efficiently than my
workaround using IndexOf and ToLower to get a case insensitive find.

Steve

Paul E Collins said:
Steve Barnett said:
[...] It looks like RichTextBoxFinds.Reverse
always starts from the end of the rich text box.

Apparently, you need to swap two of the parameters.

See http://tinyurl.com/d6xff

P.
 
Back
Top