有什么可能的方法通过字体大小/样式/颜色来搜索richTextBox? [英] Any possible way to search a richTextBox by font size/style/color?

查看:73
本文介绍了有什么可能的方法通过字体大小/样式/颜色来搜索richTextBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序内有一个扩展的richTextBox,用户可以在其中填充文本..我有一些用于不同格式设置选项的按钮.
假设在文本内有3-4章.这些章节的标题均使用相同的样式/字体/颜色编写.我想要的是一种在文本文档中标识那些标题的方法.

I have an extended richTextBox inside an app, which is to be filled with text by the user.. I have some buttons for different formating options.
Let''s say inside the text there are 3-4 chapters. The titles of the chapters are all written using the same style/font/color. What I want is a means to identify those titles inside the text document.
Any ideas?

推荐答案

不是最优雅的方法是简单地遍历文本,一个接一个地选择每个字符,获取其字体并匹配属性您正在寻找.每次找到匹配项时,您只需保持在开始位置,然后通过查找不匹配项或文本的结尾来搜索结尾.

在这里,您有一个示例如何检查字体.遍历和选择应该是小菜一碟.

http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionfont.aspx [ ^ ]

也许本文在代码项目上的这篇文章也可能会有所帮助,并且可以为您提供另一种搜索这些字体属性的方法.

NRTFTree-在C#中用于RTF处理的类库 [
Not the most elegant way would be to simply traverse the text, selecting each character one by one, get it''s font and match the properties you are looking for. Each time a match is found you simply hold on to the start position and then search for the end by finding a mismatch or the end of the text.

Here you have a sample how to check the font. Traversing and selecting should be a peace of cake.

http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionfont.aspx[^]

Maybe this article here on the codeproject might also be helpful and could supply you with another way of searching on these font properties.

NRTFTree - A class library for RTF processing in C#[^]

Good luck!


这篇关于有什么可能的方法通过字体大小/样式/颜色来搜索richTextBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆