在 RichTextBox 中查找字体样式的字符索引
我正在寻找一种有效的方法来查找 RichTextBox 中不同字体样式的字符索引。我有以下内容:
for (var i = 0; i < index; i++)
{
_activeCopyBox.Select(i, 1);
if (!linkFound && _activeCopyBox.SelectionFont.Underline)
underLineFound = true;
}
然而,这非常慢,因为它必须一次选择每个字母。我可以从 Rft 中获取格式,但尝试以这种方式找到字符的正确索引很混乱。
如果有人知道更好的方法(一定有),我很想听听。
提前致谢。
I'm looking 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要 .Rtf 属性,这为您提供了基础 RTF 信息,包括所有特殊标记,最终会在 RichTextBox 中加下划线和粗体,并以其他方式格式化信息。
以下是 RTF 标记的链接,它可能会帮助您更有效地完成任何操作:
http://msdn.microsoft.com/en-us/library/aa140277%28office.10%29.aspx
搜索“下划线”和“粗体”即可将看看它是如何工作的。最有可能需要使用正则表达式来快速有效地获取您想要的信息。
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.