Controls.RichTextBox 与 Forms.RichTextBox [英] Controls.RichTextBox vs. Forms.RichTextBox

查看:35
本文介绍了Controls.RichTextBox 与 Forms.RichTextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我目前需要一个 RichTextBox 控件来在编辑时突出显示某些文本(某种语法突出显示).

In my Project i currently need a RichTextBox control for highlighting some Text whilst editing it (some kind of Syntax highlighting).

我尝试将 System.Windows.Controls.FlowDocument 放入 RichTextBox.但是有两个!

What I tried was to put a System.Windows.Controls.FlowDocument in a RichTextBox. But There are two of them!

一个 (Windows.Forms.) 可以应用于表单,另一个 (Windows.Controls.) 不能,但第二个可以处理 FlowDocuments.

One (Windows.Forms.) can be applied to the form, the other (Windows.Controls.) cannot, but the second one can handle FlowDocuments.

任何提示如何解决我的烂摊子?

Any hints how to solve my mess?

也欢迎使用其他方法来跟踪文本块并根据用户输入更改其格式!

Other methods, to be able to track a Textblock, and change its formatting depending on user input would be also welcome!

推荐答案

查看 ICSharpCode.这具有完整的语法突出显示和丰富的文档.使用它比编写自己的编辑器要容易得多.

Have a look at ICSharpCode. This has full syntax highlighting and a wealth of documentation. Using this will be much easier than writing your own editor.

但是,如果您需要 RichTextBox 功能,您可以覆盖 RichTextBox 本身并使用计时器根据正则表达式匹配项来突出显示文本.第二种方法需要一个缓冲策略来避免突出显示/编辑整个 RichTextBox 控件...

However, if you require RichTextBox features, you could override the RichTextBox itself and use a timer to hightlight text based on the matches from a regex say. This second aproach will need a buffer strategy to avoid highlighting/editing the entire RichTextBox control...

我希望这会有所帮助.

这篇关于Controls.RichTextBox 与 Forms.RichTextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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