Finding the char index of a Font Style in a RichTextBox
I'm looking开发者_JAVA百科 for an efficient way to find the character indexes of different font styles in a RichTextBox. I have the following:
for (var i = 0; i < index; i++)
{
_activeCopyBox.Select(i, 1);
if (!linkFound && _activeCopyBox.SelectionFont.Underline)
underLineFound = true;
}
This however is very slow as it has to select each letter one at a time. I can get the formatting out of the Rft but it is messy trying to find the correct index of the charater this way.
If someone knows a better way (there must be one) I'd love to hear it.
Thanks in advance.
I think you want the .Rtf property, this gives you the underlying RTF information including all the special tags and such that ultimately underlines and bolds and otherwise formats the information in the RichTextBox.
Here's a link to the RTF markup that will probably help with whatever your trying to do, much more efficiently:
http://msdn.microsoft.com/en-us/library/aa140277%28office.10%29.aspx
Search for 'underline' and 'bold' and you'll see how it works. Most likely need to use Regular Expressions to get at the information you want quickly and efficiently as well.
精彩评论