格式文本框如何突出文本块无选择 [英] Rich Text Box how to highlight text block without select

查看:93
本文介绍了格式文本框如何突出文本块无选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在RTB文本的某一部分要在改变的字体样式/彩色的感不突出,但在制造一个块选择与特定颜色的感觉。这类似于Visual Studio中如何突出期间调试模式的线。

I need a certain portion of my text in RTB to be highlighted not in the sense of changing the font style/color, but in the sense of making a block selection with a particular color. This is similar to how Visual Studio highlights a line during debug mode.

这里最重要的是要实现提到的功能的使用richtextbox.select功能,因为在RichTextBox我正在定期更新,如果它调用了select函数每次更新时,用户会有困难的时候拖动文字,我不希望这样的事情发生。

The important thing here is to achieve the mentioned feature WITHOUT using richtextbox.select function, because the richtextbox I have is being periodically updated and if it calls the select function on each update, the user will have a difficult time dragging the text and I don't want that to happen.

我听说某处一个解决方案,并编辑RTF的线,但我不能完全肯定如何做到这一点。我想AP preciate给予任何帮助。

I've heard a solution somewhere along the line of editing the rtf but I'm not entirely certain how to do this. I'd appreciate any help given.

推荐答案

编辑:刚刚意识到问题是的WinForms。以下的答案必须为WPF,而不是删除我要离开它,万一有人发现它有用。

Just realized question is for winforms. The following answer is for WPF, rather than delete I'm gonna leave it, in case someone find it useful.

获取使用的TextRange(...)文本和应用背景 例如:

Get the text using TextRange(...) and apply Background for example:

TextRange tr = new TextRange(position, nextPosition);
var Br = new SolidColorBrush(Color.FromScRgb(alpha, 1f, 1f, 0f));
tr.ApplyPropertyValue(TextElement.BackgroundProperty, Br);

但是,也许你应该考虑你的更新机制,并拿出一个更好的解决方案。

But perhaps you should look into your update mechanism and come up with a better solution.

这篇关于格式文本框如何突出文本块无选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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