How to highlight portion of a Rich TextBox WPF control if there are more than 2 spaces?

跟風遠走 提交于 2020-02-23 04:15:30

问题


I have a richtextbox control in my WPF 4.0 application. Now suppose I have a text like

"hello how [space][space] r u? [space][space] I am fine"

As can be noticed that there are two gaps between how and r as well as between ? and I.

When this will happen then the portion will be highlighted with green e.g. how ..r and from ? to I will be highlighted with green color.

i.e. if the space between two words are more than 2 then that will be highlighted with green.

Is it possible to do in WPF RichTextbox control? If so, please help me in writing so. As of now what I have done is that I have only able to find out the distance of spaces between two words.

Note:~ [Space] means the white spaces. Since the gap was not prominent(as it was not coming in the editor), that's the reason I made it like so.

Thanks

WPF4.0/ C#4.0


回答1:


http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7c9a622a-4e3b-451e-bc4c-ab9d011447e0

Here is a progressive scenario featuring RichTextBox highlighting multiple ranges, it may lead you on the right path.

He ends up getting it to work, but you will have to modify it to recognize white space perhaps.



来源:https://stackoverflow.com/questions/3924553/how-to-highlight-portion-of-a-rich-textbox-wpf-control-if-there-are-more-than-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!