I am developing a Windows Form application. I use RichTextBox.LoadFile
method to load text from a file and highlight some portion of the text. The text in the file contains return characters.
Suppose that I want to highlight the highlight
. First I find the startIndex
and the length
of the the highlight
part, then use RichTextBox.Select(startIndex, length)
and give some color to it.
When I use SubString
method, I can find the correct text. But when I apply the same value of startIndex
and length
to Select
method, the highlighted part becomes [space][space][space]the highli
. It looks the Select
method takes some return characters into account and cause some problem.
How can I resolve it?
first time i hear about it and i use the
richTextBox
a lot. try to useSubString
to find the substring you want on therichTextBox.Text
instead of the string from the file. if you are already do it try to check the return number from substring method and see if it reference the right location.also, please share your code please, i want to see it for myself. if it is a .net problem then i need to go over my work...
This is how I "Search" for a specific text in a RichTextBox then highlight it to RED
I think you should use the
Find()
method ofRichTextBox
: